Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
879 views
in Technique[技术] by (71.8m points)

spring boot - Return empty string instead of null in SpringBoot Web response

I am trying to get an empty string instead of null in the response from a HTTP rest controller in a Spring Boot Web project.

The return code is as follows: an ArrayNode class wrapped into ResponseEntity

return new ResponseEntity<>(result, HttpStatus.OK);

The image below shows that it is a NullNode in the response and the second image shows the response in Postman. I would like the contactNumber field to be empty string instead of null.

enter image description here enter image description here

question from:https://stackoverflow.com/questions/66060765/return-empty-string-instead-of-null-in-springboot-web-response

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You must define your own CustomNullStringSerializerProvider and call him in your ObjectMapper

https://digitaljoel.nerd-herders.com/2015/03/18/how-to-make-jackson-serialize-null-strings-differently-than-null-objects/

Josselin


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...