Re: Partial JSON deserialization

Andy Guibert
 

you could accomplish this by defining your "data" field type as type javax.json.JsonObject so you can work with it raw:

public class Foo {
  public String type;
  public JsonObject data;
}

A more elegant solution would be to write a custom javax.json.bind.adapter.JsonbAdapter and reference it using @JsonbTypeAdapter on your data model class, for example:

public class Foo {
  @JsonbTypeAdapter(FooDataAdapter.class)
  public FooData data;
}

The advantage of this approach would be that you can implement your own adapt{To,From}Json() methods where you could inspect the data to determine the concrete type in the case FooData has multiple subclasses (I'm guessing this is what you're trying to achieve by encoding the type information in the JSON)

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