I am giving up. I have looked through all possible SO pages but I can not get it to work.
I have a class ConfigKeyVal
like this:
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConfigKeyValue {
private String name;
private NssConfigDto value;
}
Where Config
class looks like this:
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Config {
private String name;
private String source;
private String destination;
private int cycle;
private LocalDateTime fixedTime;
private LocalDateTime submitDate;
}
I am trying to deserialize JSON array of ConfigKeyVal
(top one) objects directly into the ArrayList of mine.
public class ConfigKeyValueList extends ArrayList<ConfigKeyValue> {
public ConfigKeyValueList() {
super();
}
}
Like this:
final Data values = result.results().get("attributes"); // this is an array of ConfigKeyValue objects
ObjectMapper mapper = new ObjectMapper();
ConfigKeyValueList configKeyValueList = new ConfigKeyValueList();
try {
configKeyValueList = mapper.readValue(values.asText(), ConfigKeyValueList.class);
} catch (IOException e) {
e.printStackTrace();
}
I have tried using mapper.registerModule(new JavaTimeModule());
but that did not help. Do I have to write my own deserializer for this or is there a valid tool and I am doing it all wrong?
The error I am getting is: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.time.LocalDateTime: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?))
I am using those jackson dependencies in my gradle file:
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names', version: '2.9.6'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jdk8', version: '2.9.6'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.6'
EDIT: This is how JSON looks like
[
{
"name": "kek1",
"value": {
"name": "kek1",
"source": "source",
"destination": "dest",
"cycle": 1,
"fixedTime": {
"year": 2017,
"month": "APRIL",
"dayOfYear": 95,
"dayOfWeek": "WEDNESDAY",
"dayOfMonth": 5,
"monthValue": 4,
"hour": 4,
"minute": 20,
"second": 0,
"nano": 0,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
},
"submitDate": {
"year": 2017,
"month": "APRIL",
"dayOfYear": 95,
"dayOfWeek": "WEDNESDAY",
"dayOfMonth": 5,
"monthValue": 4,
"hour": 4,
"minute": 20,
"second": 0,
"nano": 0,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
}
}
},
{
"name": "kek2",
"value": {
"name": "kek2",
"source": "source",
"destination": "dest",
"cycle": 1,
"fixedTime": {
"year": 2017,
"month": "APRIL",
"dayOfYear": 93,
"dayOfWeek": "MONDAY",
"dayOfMonth": 3,
"monthValue": 4,
"hour": 5,
"minute": 10,
"second": 0,
"nano": 0,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
},
"submitDate": {
"year": 2017,
"month": "APRIL",
"dayOfYear": 93,
"dayOfWeek": "MONDAY",
"dayOfMonth": 3,
"monthValue": 4,
"hour": 5,
"minute": 10,
"second": 0,
"nano": 0,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
}
}
}
]