Skip to content

Tag: objectmapper

ObjectMapper writeValueAsString on ‘null’ vs ‘NullNode.getInstance()’

Consider the following statements: String s1 = new ObjectMapper().writeValueAsString(null); String s2 = new ObjectMapper().writeValueAsString(NullNode.getInstance()); In both the cases, serialized values s1 and s2 would be “null” (in String format). Jackson, by default, serializes null objects without any exception. What are the cases where we need to use NullNode, instead of directly serializing null? Answer “null” here is a string, not

No serializer found when serializing one Object

I’m trying to return an Object as JSON. Using the /user/id endpoint, I want to display a User based on his Id. When calling this controllerMethod I get the following Exception: My contollerClass looks like this: I checked if al fields have a public getter and tried various options with @JSONIgnoreProperties, but I can’t find it. Displaying all users as