Comments (5)
You can do $visitor->setNavigator($navigator); in your handler if you are doing $navigator->accept on a subitem.
from serializer.
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.
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.
That's what the library also does https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/Handler/FormErrorHandler.php#L148-L150
from serializer.
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)
- Type Error in XmlDeserializationVisitor.php when switching to PHP 8 HOT 3
- The serializer cannot be installed in a Laravel version 10 project. HOT 2
- Update doctrine/instantiator to v2.x for PHP 8.1 HOT 5
- JMS serializer implements Symfony serializer HOT 4
- "Can't use incorrect type integer for collection" on PHPDoc-typed integer, boolean or double HOT 1
- stdClass Serialization Does Not Use Property Naming Strategy HOT 3
- Question: How to handle de-/serializing unions (using native type hints)? HOT 5
- Serialization of Symfony\Component\Mime\Address HOT 4
- Undefined property: JsonDeserializationVisitor::$navigator sence version 3.23 HOT 2
- The dependency on doctrine/annotations should become an optional one HOT 2
- Minor Issue from Triggering Autoload Before Expanding Class Names HOT 2
- ORM 3.0 Compat HOT 8
- Adding tideways spans inside JMS serializer HOT 5
- Serialization of objects with missing attribute errors HOT 2
- AccessType attribute constructor expects array HOT 3
- Feature request: Allow literal discriminator values HOT 2
- Use another field than "id" to find Doctrine entity HOT 3
- Change to optional Doctrine/Annotations package introduces a breaking change HOT 10
- Enum deserializer
- Missing fields are replaced with null HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serializer.