Re: Partial JSON deserialization

Andy Guibert
 

I think you can still achieve what you need with an adapter, consider this JSON data:


  type: "com.Foo"
  data: {
    value: "Hello"
  }
}

in your adapter, you check the type, then depending on the type you can use Jsonb#fromJson(String, Class<?>) to get a POJO of the correct target class.  So something like:
if("com.Foo".equals(map.get("type)))
  return jsonb.fromJson(map.get("data"), Foo.class);

Or more generically you can verify the type is an "allowed type" and then use reflection after that point so you don't end up with a bunch of `if` statements

Your use case seems to be spot on for this unit test over in Yasson:
https://github.com/eclipse/yasson/blob/master/src/test/java/org/eclipse/yasson/adapters/PolymorphicAdapterTest.java
https://github.com/eclipse/yasson/blob/master/src/test/java/org/eclipse/yasson/adapters/model/LocalPolymorphicAdapter.java

Join jsonb-spec@javaee.groups.io to automatically receive all group messages.