Re: Partial JSON deserialization

Richard Evans



Thanks for this.  I had considered this approach … but then I have to handle the map elements manually.  And if the attribute defining the polymorphic type is outside the object itself, in some outer JSON then the adapter approach does not work.


I really want to specify that the JSON for the polymorphic object is left as raw JSON text.  Then I can get the outer object using Jsonb, examine its attributes and then apply the Jsonb again to the raw string with the correct target class. 

I could get the same effect by leaving the polymorphic object as a Map<String, Object> and then using Jsonb to convert this back to a string which I then deserialized again with the correct target class.  But that seems wasteful.




From: Andy Guibert [mailto:andy.guibert@...]
Sent: 31 January 2018 14:38
Subject: Re: [jsonb-spec] Partial JSON deserialization


A JsonbAdapter can go between Map<String, ?> and the java type it's an adapter for.  In the `adaptFromJson(Map<String,?>)` method you can handle polymorphism yourself if needed.  We do this in one of our test cases for OpenLiberty for example:

In this test we have a Location interface with Pod and ReserveableRoom being two concrete implementations.  The adapter is capable fo detecting which type to convert to by inspecting the incoming map.  So I was envisioning you could check the type attribute in your adapter and use that information to determine which concrete class it maps to.

Join to automatically receive all group messages.