java - Jackson: Reuse json property as type id during deserialization -


in spring rest controller need deserialize dto:

// enum private ctype ctype;   @jsontypeinfo(use = jsontypeinfo.id.name,         include = jsontypeinfo.as.external_property,          property = "ctype") @jsonsubtypes({@type(value = initplp.class, name = "p")}) private initpl initpl;   @jsontypeinfo(         use = jsontypeinfo.id.name,         include = jsontypeinfo.as.external_property,         property = "ctype") @jsonsubtypes({@type(value = scidp.class, name = "p")}) private scid scid;   // getters ... 

when trying deserialize like:

{     "ctype": "p",     "initpl": { ... },     "scid": { ... } } 

there jsonmappingexception: unexpected token (value_null), expected value_string: need json string contains type id (for subtype of com.xmpl.initpl)

interestingly, both scid , initpl can deserialized on own. if part of same payload it'll break.

to me seems ctype can looked once during deserialization.

so basically, how can reuse typeid?

does have idea?


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -