I have an issue in my Spring projet when I call a web-service that return an object with a attribute that is an empty string.
In my projet I have Spring boot 1.5.2, Spring 4.3.7 and Jackson 2.8.7.
I use a RestTemplate to call web-services.
ResponseEntity<T> responseEntity = restTemplate.exchange("web-service-HttpMethod.GET, null, MyObject.Class);
return responseEntity.getBody();
If I call the web-service in browser, it returns this response :
{
"display_item_code": "NEP054",
"historic": false,
"popin_type_code": "",
"combo_box": false,
"max_combo_box_elements": 0,
"data_max_length": 0,
"data_precision": 0,
"data_min_length": 0,
"data_control_type_code": "",
"data_control_value1": "",
"data_control_value2": "",
"data_format": "MAJUS",
"translatable": false,
"translation_key_type_code": "",
"default_value_setting": "",
"default_value": "",
"text_area": false,
"family_code": "",
"popin": null,
"combo_values": null
}
That is the expected result. But when I call this web-service in my application, I obtain this object :
{
"display_item_code": "NEP054",
"historic": false,
"popin_type_code": null,
"combo_box": false,
"max_combo_box_elements": 0,
"data_max_length": 0,
"data_precision": 0,
"data_min_length": 0,
"data_control_type_code": null,
"data_control_value1": null,
"data_control_value2": null,
"data_format": "MAJUS",
"translatable": false,
"translation_key_type_code": null,
"default_value_setting": null,
"default_value": null,
"text_area": false,
"family_code": null,
"popin": null,
"combo_values": null
}
All the attributes that have an empty value are now null. I think there is something to configure, maybe an ObjectMapper or a JsonParser, but I don't find what to do. Currently I use the default Serializer, ObjectMapper and JsonParser. I let Spring Boot do the autoconfiguration.
How can I configure my application to keep empty string when it deserialize an object ?
EDIT : I tried this solution by adding a module to the ObjectMapper for string deserialization, but this method is never called.
EDIT 2 : In the BeanDeserializer class, during the deserialization, the JsonToken for the field "popin_type_code" is equal to JsonToken.VALUE_NULL. I don't understand how Spring/Jackson generate this JsonToken.