users@jsonb-spec.java.net

[jsonb-spec users] Adding type field to serialized object

From: Aaron Anderson <aaronanderson_at_acm.org>
Date: Sun, 19 Feb 2017 00:36:59 +0000 (UTC)

I was checking out JSON-B and the RI Yasson and how they compares to Jackson. I have an application that contains POJOs that I serialize to JSON and store in a NoSQL database. For querying purpose I would like to add a type field  in the JSON based on the class simple name. I thought the JsonbSerializer class would be ideal for this but it appears the SerializationContext methods can only directly write objects without modification. I can use the JsonGenerator to write around the object JSON but change the object JSON itself. The JavaOne2016 AnimalAdapter.java example does something similar to what I would like to do but in that example   each key/value is explicitly serialized defeating the purpose of automated object serialization. Can dynamic name/value pairs be added during serialization and read/ignored during deserialization?
Additionally I was testing with classes extending a base class that I declared a serializer and deserializer for and the serializers were not invoked unless I provided the superclass type explicitly, i.e. jsonb.toJson( object, SuperClass.class); instead of just jsonb.toJson( object); I was expecting that the type hierarchy would automatically be walked up until a registered serializer was found.
Thanks!