I am using @RestController in Spring and I have the following response:
{"name":"Khan","first":null,"last":null}
I want the null to be "" (empty string)
I do not want to do something ugly like initializing each property with an empty string like so:
@Transient private String first="";
@Transient private String last="";
I found a link that discusses how to implement this solution "for Jackson < 2.0)", but I am using Jackson libraries > 2.0 like:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.1</version>
</dependency>
Further, the solution in the link doesn't always work according to some others who tried it.
Is there an elegant way of doing a conversion from fields that have a null value to empty string? Preferably with annotations.