users@jsonb-spec.java.net

[jsonb-spec users] [jsr367-experts] Polymorphic deserializer

From: Roman Grigoriadi <roman.grigoriadi_at_oracle.com>
Date: Tue, 10 May 2016 15:42:55 +0200

According to polymorphic deserialization, which was one of the usecases
for deserializers, I encountered the fact, that if context.deserialize()
is called inside the deserializer for the type that is the return type
for that deserializer, jsonb runtime will try to use such deserializer
again inside. Example:

public class PolymorphicDeserializerimplements JsonbDeserializer<Animal> {
     @Override public Animal deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
         Class<?extends Animal> clazz =null;

         while (parser.hasNext()) {
//some code to get class, which will result to subclass of an Animal
//...
//following will cause adding PolymorphicDeserializer instance to call
stack again, calling deserialize on it
         return ctx.deserialize(clazz, parser);//--- REENTRANT CALL---
         }
         throw new IllegalStateException("animal not found!");
     }
}

Looks like this is correct behaviour, JSONB runtime has deserializer
registered for it. Without some kind of parameter flag it has no clue
not to use it. How about adding default to true method "boolean
isReentrant()" to JsonbDeserializer interface?

Thanks,
Roman