Open bennycode opened 10 years ago
Approach works very well (check https://github.com/bennyn/wlc-fire-tv/commit/a150711a2cbdfbde54926a0674b4baf22652a347). But maybe we can find a solution without a mapping class (like CategoryResult.java
). I am quite optimistic. :)
Consider using something like this
private static ObjectMapper createCombinedObjectMapper() {
return new ObjectMapper()
.configure(SerializationFeature.WRAP_ROOT_VALUE, true)
.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true)
.setAnnotationIntrospector(createJaxbJacksonAnnotationIntrospector());
}
in https://github.com/bennyn/wlc-webapp/blob/master/src/main/java/com/welovecoding/tutorial/api/v2/ObjectMapperResolver.java which maybe is a better fit to resolve this from the framework.
Yeah, maybe we should use that. I hoped that there is an annotation for it. But the createJaxbJacksonAnnotationIntrospector
should allow us to use a Jackson annotation where we can define the name for the wrapped list. At the moment it is solved with a mapping class but I will keep my eyes open for another solution. Thanks, @YserzJenkins. Up till now I thought you were only a building tool. :grin:
Verschiedene Java-JSON-Bibliotheken bieten an, bei einem REST-Call aus dem Result automatisch POJOs zu parsen. Damit das zuverlässig funktioniert, muss aber Folgendes gegeben sein:
The JSON root must be a JSON object with a key
. In unserem Fall ist die Response aber ein JSON Array und kein JSON Object.URL:
Aktuelle Rückgabe
Um einheitliche Result-Sets zu bieten, sollte unser Result immer ein JSON Object (
{ }
) sein und Rückgabewerte benennen.Beispiel