PostsPage deserialization via JMS Serializer.

This commit is contained in:
Alexey Skobkin 2016-03-22 22:57:18 +03:00
parent 3af5fd230e
commit 8f44a04989
6 changed files with 76 additions and 34 deletions

View file

@ -11,12 +11,12 @@ class CrawlerController extends AbstractApiController
$token = $request->request->get('token');
$json = $request->request->get('json');
$serializer = $this->get('serializer');
$serializer = $this->get('jms_serializer');
$data = $serializer->deserialize($json, 'Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler\PostsPage', 'json', ['groups' => ['import_post_page']]);
$page = $serializer->deserialize($json, 'Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler\PostsPage', 'json');
return $this->createSuccessResponse([
'continue' => true,
'continue' => false,
]);
}
}

View file

@ -2,21 +2,29 @@
namespace Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler;
use Symfony\Component\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation as JMSS;
/**
* @JMSS\ExclusionPolicy("none")
* @JMSS\AccessType("public_method")
*/
class MetaPost
{
/**
* @var Recommendation
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("rec")
* @JMSS\Type("Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler\Recommendation")
* @JMSS\MaxDepth(2)
*/
private $rec;
/**
* @var Post
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("post")
* @JMSS\Type("Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler\Post")
* @JMSS\MaxDepth(2)
*/
private $post;

View file

@ -2,56 +2,68 @@
namespace Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler;
use Symfony\Component\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation as JMSS;
/**
* @JMSS\ExclusionPolicy("none")
* @JMSS\AccessType("public_method")
*/
class Post
{
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("id")
* @JMSS\Type("string")
*/
private $id;
/**
* @var string[]
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("tags")
* @JMSS\Type("array<string>")
*/
private $tags;
/**
* @var User
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("author")
* @JMSS\Type("Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler\User")
* @JMSS\MaxDepth(1)
*/
private $author;
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("text")
* @JMSS\Type("string")
*/
private $text;
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("created")
* @JMSS\Type("string")
*/
private $created;
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("type")
* @JMSS\Type("string")
*/
private $type;
/**
* @var bool
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("private")
* @JMSS\Type("boolean")
*/
private $private;
@ -86,7 +98,7 @@ class Post
* @param string[] $tags
* @return Post
*/
public function setTags(array $tags)
public function setTags($tags)
{
$this->tags = $tags;
return $this;

View file

@ -2,19 +2,26 @@
namespace Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler;
use Symfony\Component\Serializer\Annotation as Serializer;
use Doctrine\Common\Collections\ArrayCollection;
use JMS\Serializer\Annotation as JMSS;
/**
* @JMSS\ExclusionPolicy("none")
* @JMSS\AccessType("public_method")
*/
class PostsPage
{
/**
* @var MetaPost[]
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("posts")
* @JMSS\Type("array<Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler\MetaPost>")
* @JMSS\MaxDepth(3)
*/
private $posts;
/**
* @return MetaPost[]
* @return MetaPost[]|ArrayCollection
*/
public function getPosts()
{
@ -22,10 +29,10 @@ class PostsPage
}
/**
* @param MetaPost[] $posts
* @param MetaPost[]|ArrayCollection $posts
* @return PostsPage
*/
public function setPosts(array $posts)
public function setPosts($posts)
{
$this->posts = $posts;
return $this;

View file

@ -2,28 +2,36 @@
namespace Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler;
use Symfony\Component\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation as JMSS;
/**
* @JMSS\ExclusionPolicy("none")
* @JMSS\AccessType("public_method")
*/
class Recommendation
{
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("text")
* @JMSS\Type("string")
*/
private $text;
/**
* @var int|null
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("comment_id")
* @JMSS\Type("integer")
*/
private $comment_id;
private $commentId;
/**
* @var User
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("author")
* @JMSS\Type("Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler\User")
* @JMSS\MaxDepth(1)
*/
private $author;
@ -49,18 +57,18 @@ class Recommendation
/**
* @return int|null
*/
public function getComment_id()
public function getCommentId()
{
return $this->comment_id;
return $this->commentId;
}
/**
* @param int|null $comment_id
* @param int|null $commentId
* @return Recommendation
*/
public function setComment_id($comment_id)
public function setCommentId($commentId)
{
$this->comment_id = $comment_id;
$this->commentId = $commentId;
return $this;
}

View file

@ -2,28 +2,35 @@
namespace Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler;
use Symfony\Component\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation as JMSS;
/**
* @JMSS\ExclusionPolicy("none")
* @JMSS\AccessType("public_method")
*/
class User
{
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("id")
* @JMSS\Type("integer")
*/
private $id;
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("login")
* @JMSS\Type("string")
*/
private $login;
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
* @JMSS\SerializedName("name")
* @JMSS\Type("string")
*/
private $name;