Closed herau closed 9 years ago
This is how it is supposed to work: class annotations have higher precedence than serializers registered for types.
But you can override annotations by using mix-in annotations.
there is no way to have this kind of features (mix-in) but with JsonSerializer ? because JsonSerializer suppose to be more efficient that declare annotations on POJO
No: priority is well-defined in that more specific (annotations to the property or class) overrides less specific (general by-type registrations). There is no performance difference between mix-in annotations, regular annotations or registration: serializer to use is determined once and cached.
In this wiki https://github.com/FasterXML/jackson-docs/wiki/Presentation:-Jackson-Performance, Streaming API should be more efficient than data binding (annotations). So did i loose in performance when i use annotations compared to serializer (streaming API) ? Because my understanding is that only mix-in can solve my problem.
If you use annotations, you are already using databind, not pure streaming. So there is no difference.
Reference to using Streaming API only means that if you write your own low-level code with direct JsonParser
and JsonGenerator
calls, it can be even faster than going through automatic handling of properties by JsonSerializer
and JsonDeserializer
. But all annotations are equal in that they are read once, and used to construct deserializer/serializer; after construction annotations are not checked again during runtime when using same ObjectMapper
(different ObjectMapper
s do have their own caches for (de)serializers, which is how you can use different mix-ins, but only with different mappers).
Hello,
I have a class with a default JsonSerializer.
But sometimes i want to serialize this class in another way. so i have another JsonSerializer
But when i try to use this serializer, the default serializer is selected instead of my custom serializer