Jackson deserialization of type with different objects

前端 未结 4 1548
清酒与你
清酒与你 2020-12-06 02:21

I have a result from a web service that returns either a boolean value or a singleton map, e.g.

Boolean result:

{
    id: 24428,
    rated: false
}
<         


        
4条回答
  •  死守一世寂寞
    2020-12-06 02:44

    I asked a similar question - JSON POJO consumer of polymorphic objects

    You have to write your own deserialiser that gets a look-in during the deserialise process and decides what to do depending on the data.

    There may be other easier methods but this method worked well for me.

提交回复
热议问题