pleerock
pleerock

Reputation: 18846

JMSSerializerBundle - continue deserialization in the custom handler

I have a custom handler that performs deserialization of my object:

public function deserialize(   JsonDeserializationVisitor $visitor,
                               $data,
                               array $type,
                               DeserializationContext $context)

I don't want to take all deserialization job on my own, I only want to do some of that. For example, I have an Album (id, name, description, photos) and I want to deserialize "description" by myself, and left all other job to the bundle.

    if (!empty($data['id']))
        $album = $albumManager->createWithId($data['id']);
    else
        $album = $albumManager->create();

    $album->setDescription($albumDescriptionParser->parse($data['description']));

    // and now I want to delegate other deserialization job to JMSSerializer
    // ....

    return $album;

I know this is done using context, visitor and navigator, but I cant figure how

Upvotes: 1

Views: 824

Answers (1)

pleerock
pleerock

Reputation: 18846

Okay, I found the way to implement that. It seems it cannot be easy handled in the deserialization handler.

Instead, I used my custom ObjectConstructorInterface interface implementation and serializer.post_deserialize event.

Creation process can be handled in the custom ObjectConstructorInterface implementation and all "extra settings" can be set after deserialization actually done - when serializer.post_deserialize event occur.

Upvotes: 1

Related Questions