On Wed, May 22, 2019 at 12:40 PM 'ilker cam' via jackson-user <jackson-user@googlegroups.com> wrote: > > Hi, > > I have a property which can be an integer or an object without any explicit > `type` property. I tried to use JsonDeserialize annotation and provide a > custom deserializer; > > data class Report(val measures: List<IntOrMeasure>) > > @JsonDeserialize(using=IntOrMeasureDeserializer::class) > sealed class IntOrMeasure { > data class MeasureDefinition(val collection : > DataMappingHttpService.RakamCollection, val name : String) : IntOrMeasure() > data class MeasureId(val id : Int) : IntOrMeasure() > } > > class IntOrMeasureDeserializer : JsonDeserializer<IntOrMeasure>() { > override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): > IntOrMeasure { > return if(p!!.currentToken().isNumeric) { > p.readValueAs(IntOrMeasure.MeasureId::class.java) > } else { > p.readValueAs(IntOrMeasure.MeasureDefinition::class.java) > } > } > } > > > p.readValueAs(IntOrMeasure.MeasureId::class.java) recursively calls > deserialize again thus resulting with overflow. > Any insights are appreciated, thanks.
What happens when you call `readValueAs()` is that parser calls back to ObjectMapper linked to parser, asks for deserializer registered for given type, calls its `deserialize()` method. So the question would be what specifically is registered to handle `MeasureId` or `MeasureDefinition`. If it's the same deserializer implementation for some reason (maybe due to subclassing?) then there'd be infinite loop. I hope this helps, -+ Tatu +- -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user+unsubscr...@googlegroups.com. To post to this group, send email to jackson-user@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAL4a10g46RUW9arxbL-3UhiZG40ge-5o3ZQ0CjX4Jp2qRBEBeg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.