I want to deserialize a json String containing LocalDateTime fields in to a class using gson.
But this throws nullpointer exceptions.
My JSON:
metrics": {
"measurements": [
{
"serviceName": "myService",
"start": {
"year": 2018,
"month": "APRIL",
"dayOfMonth": 26,
"dayOfWeek": "THURSDAY",
"dayOfYear": 116,
"monthValue": 4,
"hour": 18,
"minute": 53,
"second": 51,
"nano": 243000000,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
},
"stop": {
"year": 2018,
"month": "APRIL",
"dayOfMonth": 26,
"dayOfWeek": "THURSDAY",
"dayOfYear": 116,
"monthValue": 4,
"hour": 18,
"minute": 53,
"second": 51,
"nano": 841000000,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
},
"processingTime": 598
}
The code i use to get my object:
Metrics metrics = gson.fromJson(jsonString, Metrics.class);
But gson is only able to deserialize the processingTime field of my object.
I've tried this too:
Java 8 LocalDateTime deserialized using Gson
but this results in
Caused by: java.lang.IllegalStateException: This is not a JSON Primitive.
at com.google.gson.JsonElement.getAsJsonPrimitive(JsonElement.java:122)
at com.foo.config.AppConfig.lambda$gson$1(AppConfig.java:63)
any thoughts?
Thanks