0

I have this simple controller that receives a map as input:

@RequestMapping(value = "/providers", method = RequestMethod.PATCH, headers = "Accept=application/json")
    @ResponseBody
    @Transactional
    public Map<String, Object> updateProvider(@RequestBody Map<String, Object> updates,
            UriComponentsBuilder uriComponentsBuilder, final HttpServletRequest request) {
        return updates;
    }

and I have this property configured in Spring Boot in the application.properties file:

spring.jackson.default-property-inclusion=non_empty

Then, if I make a PATCH request with following JSON object.

{
    "name":"frndo",
    "lastname":""
}

The content of result in the RESPONSE is:

{
  "name":"frndo"
}

But the content of input in the REQUEST is:

{
    "name":"frndo",
    "lastname":""
}

My question is, Why the content in the REQUEST is different in the RESPONSE if to serialize the Map object you have a global configuration like:

spring.jackson.default-property-inclusion=non_empty

Precisely why when @RequestBody Map<String, Object> updates arrives have the name and lastname fields if lastname is empty?.

In the RESPONSE you can see the effect of the configuration but in the REQUEST is not seen. What is the explanation of this, if the mapper had to convert the JSON to a java object, and in that process the global configuration had to be applied?

I expected to have the same content in the REQUEST and the RESPONSE

Many thanks!

AlejoDev
  • 4,345
  • 9
  • 36
  • 67
  • That property is only used during serialization i.e. converting Java object to JSON. So why do you think it would affect the request where the opposite i.e. deserialization is happening? – Vasan Apr 23 '18 at 23:51
  • OK, That's my question, I thought it was used both for serialization and for deserialization. Are you sure of this? – AlejoDev Apr 23 '18 at 23:56
  • See [here](https://fasterxml.github.io/jackson-annotations/javadoc/2.5/com/fasterxml/jackson/annotation/JsonInclude.Include.html) : "Enumeration used with JsonInclude to define which properties of Java Beans are to be included in serialization. ". That is what this property represents. Also, see [this answer](https://stackoverflow.com/questions/39005703/jackson-annotations-difference-between-jsonignorepropertiesignoreunknown-true) – Vasan Apr 24 '18 at 00:06
  • OK, you can place your answer, to help others who have the same question. Thanks! – AlejoDev Apr 24 '18 at 00:10

0 Answers0