I have a simple class in java like below:
class Simple {
private String name;
private String email;
}
I want to have behaviour of java.util.List<Simple>
and Simple
both according to input data that my program receives.
i.e.
Case 1:: if my program receives below kind of json-array input
{"simple" : [ {"name":"a", "email" : "a@z.com"}, {"name":"b", "email" : "b@z.com"} ]}
I need to parse it using List<Simple>
Case 2:: if my program receives below kind of json-object input
{"simple" : {"name":"c", "email" : "c@z.com"} }
I need to parse it using Simple
Note: I have tried using JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY
, but the problem is it is basically converting single value also into json-array at the time of writing json.
I need to persist json as it is, is there any other way to achieve this?