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 the structure i 've created in java.
public class Message<T> {
private Timestamp time;
private RestAction action;
private String type;
private List<T> data;
}
Through Class.forName();
I can get the class which represents the data in the list. The question is how can I read the List.
You need to annotate your class with
@JsonDeserialize(using = MessageDeserializer.class)
and implement custom deserializer:@see examples here: How Do I Write a Jackson JSON Serializer & Deserializer?
Something which is much shorter:
If you need to map the incoming json to your List you can do like this
Edit
Something like this, completly untested and never done
If you need to read json in generic List, Do something like
your json list object and your bean class is
now you can read this json using HashMap
something like