Jackson read json in generic List

后端 未结 4 791
旧时难觅i
旧时难觅i 2020-12-24 13:36

I\'m using Jackson in order to read json messages. One of the values that I\' trying to parse is a List and another value contains the type of the data in the list. This is

4条回答
  •  心在旅途
    2020-12-24 14:01

    You need to annotate your class with @JsonDeserialize(using = MessageDeserializer.class) and implement custom deserializer:

    public class MessageDeserializer extends JsonDeserializer {
      @Override
      public Message deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
        // YOU DESERIALIZER CODE HERE
      }
    }
    

    @see examples here: How Do I Write a Jackson JSON Serializer & Deserializer?

提交回复
热议问题