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

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

Ansible warning on jinja2 braces on when -

html - How to custom Bootstrap grid height? -