Giter VIP home page Giter VIP logo

Comments (5)

henrikbjorn avatar henrikbjorn commented on June 28, 2024

You can do $visitor->setNavigator($navigator); in your handler if you are doing $navigator->accept on a subitem.

from serializer.

HarmenM avatar HarmenM commented on June 28, 2024

I don't see how that would be a solution to the problem stated in this issue report. The handler is supposed to return custom formatted data. In the case of a child item, this data is serialized. However, if the data is on the root level, the serializer returns NULL.

from serializer.

seiffert avatar seiffert commented on June 28, 2024

I'm experiencing the same problem.
The issue is that the visitor does not know about any root as long as you don't explicitly set one via $visitor->setRoot() or by "visiting" a value via $visitor->visit<Type>().

A workaround/hack is to normalize your object into an array and set this array as the root of the visitor:

public function serializeMyClassToJson(JsonSerializationVisitor $visitor, MyClass $obj, array $type, SerializationContext $context)
{
    $result = array(
        ...
    );

    $visitor->setRoot($result);

    return $result;
}

Besides working around the library, this of course does not work when the object of type MyClass is embedded in another object that should be serialized (without a custom handler that uses the same hack).

from serializer.

adrienbrault avatar adrienbrault commented on June 28, 2024

That's what the library also does https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/Handler/FormErrorHandler.php#L148-L150

from serializer.

goetas avatar goetas commented on June 28, 2024

Fixed in 2.0, now the visitors do not use an internal data representation, but the data are passed always back an forward to the graph navigator and serialized/deserialized with the new SerializationVisitorInterface::getResult($data) and DeserializationVisitorInterface::getResult($data) methods

from serializer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.