After updating the Jackson library, the response changed, previously Json.toJSON(LocalDateTime.now()) was used, which calls ObjectMapper().valueToTree(data);
I want the view to be the same as before :
"date": {
"year": 2022,
"month": "SEPTEMBER",
"dayOfMonth": 8,
"dayOfWeek": "THURSDAY",
"dayOfYear": 251,
"monthValue": 9,
"hour": 16,
"minute": 4,
"second": 30,
"nano": 0,
"chronology": {
"calendarType": "iso8601",
"id": "ISO"
}
}
now the answer looks like this:
[2022,9,20,11,28,9,598000000]
Before updating the libraries, serialization of the LocalDateTime object in JsonNode was enough to get the right answer, now I tried in different ways -
final String jsonNode = new ObjectMapper().findAndRegisterModules().writeValueAsString(LocalDateTime.now());
return ok(Json.toJson(jsonNode));
or this without Json.toJson(jsonNode), just :
final String jsonNode = new ObjectMapper().findAndRegisterModules().writeValueAsString(LocalDateTime.now());
return ok(jsonNode);
or:
final JsonNode jsonNode = new ObjectMapper().registerModule(new JSR310Module()).valueToTree(LocalDateTime.now());
return ok(Json.toJson(jsonNode));
and various other options, which, unfortunately, do not give the desired effect even if I do not use Json.toJSON();
Json.toJson() (code):
public static JsonNode toJson(final Object data) {
try {
return mapper().valueToTree(data);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
I use Play and sbt for compilation, it is important for me not to change the code of the entire project just because of updating the libraries, but it should be noted that I needed to update them because some new modules that needed to be added are not compatible with the old version of Jackson. Dependencies look like this
libraryDependencies += "com.fasterxml.jackson.dataformat" % "jackson-dataformat-cbor" % "2.12.6"
libraryDependencies += "com.fasterxml.jackson.datatype" % "jackson-datatype-jdk8" % "2.12.6"
libraryDependencies += "com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.12.6"
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-annotations" % "2.12.6"
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-core" % "2.12.6"here
I will be very grateful for the answer, if it is possible to do this