Jackson will give you null for other objects, but for String it will give empty String.

But you can use a Custom JsonDeserializer to do this:

class CustomDeserializer extends JsonDeserializer<String> {

    @Override
    public String deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException, JsonProcessingException {
        JsonNode node = jsonParser.readValueAsTree();
        if (node.asText().isBlank()) {
            return null;
        }
        return node.toString();
    }

}

In class you have to use it for location field:

class EventBean {
    public Long eventId;
    public String title;

    @JsonDeserialize(using = CustomDeserializer.class)
    public String location;
}
Answer from Sachin Gupta on Stack Overflow
🌐
GitHub
github.com › FasterXML › jackson-databind › issues › 1563
ACCEPT_EMPTY_STRING_AS_NULL_OBJECT doesn't work. · Issue #1563 · FasterXML/jackson-databind
March 17, 2017 - public class NullCheckTest { @Test public void testObjectMapper() throws Exception { final HelloForm form = new HelloForm(); form.setName(""); final ObjectMapper mapper = new ObjectMapper(); mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); final String text = new ObjectMapper().writeValueAsString(form); final HelloForm newForm = mapper.readValue(text, HelloForm.class); assert newForm.getName() == null; } private static class HelloForm { String name; public String getName() { return name; } public void setName(final String name) { this.name = name; } } } I tried to use this property in my spring boot project as documented in reference. After a detailed tracking I noticed it's an issue about Jackson. spring.jackson.deserialization.accept-empty-string-as-null-object = true ·
Author: FasterXML
🌐
GitHub
github.com › FasterXML › jackson-dataformats-text › issues › 130
Empty String deserialized as `null` instead of empty string · Issue #130 · FasterXML/jackson-dataformats-text
April 25, 2019 - I have managed to trace the diverging behavior in com.fasterxml.jackson.dataformat.yaml.YAMLParser#_decodeScalar. The 2.6 version was evaluating the field to JsonToken.VALUE_STRING while the 2.9 version is using SnakeYaml implicit resolvers and evaluates to JsonToken.VALUE_NULL. What is the desirable way to keep the behavior from 2.6, deserialize empty fields to empty string instead of null, after migrating to 2.9?
Author: FasterXML
🌐
Baeldung
baeldung.com › home › json › jackson › setting default values to null fields in jackson mapping
Setting Default Values to Null Fields in Jackson Mapping | Baeldung
July 8, 2026 - Instead, we can implement a setter method for maximum control. Thus, we can set a null to a desired value. On the other hand, a null value can also be set to an empty string in the setter method.
🌐
Stack Overflow
stackoverflow.com › questions › 65113997 › jackson-2-convert-api-response-empty-string-to-null
spring boot - jackson 2 - Convert API response empty string to null - Stack Overflow
December 2, 2020 - Because by default you would get the null for each field which does not have any value set during the period , unless you have used some "@JsonInclude(JsonInclude.Include.NON_NULL)" which will make only non null json to be dislayed . something like below. { "system": "mySystem", "created": null, "createdBy": null }
🌐
Stack Overflow
stackoverflow.com › questions › 20654810 › jackson-deserializing-null-strings-as-empty-strings
java - Jackson: deserializing null Strings as empty Strings - Stack Overflow
I have the following class, that is mapped by Jackson (simplified version): public class POI { @JsonProperty("name") private String name; } In some cases the server returns "name": null an...
Find elsewhere
Top answer
1 of 2
9

You will have to write a custom Jackson Serializer - a good example is here - http://wiki.fasterxml.com/JacksonHowToCustomSerializers (there is a specific example of how to convert null values to empty Strings that you can use)

Here are all the steps(for Jackson < 2.0):

Write your custom null Serializer:

import java.io.IOException;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;

public class NullSerializer extends JsonSerializer<Object> {

    @Override
    public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
        jgen.writeString("");
    }
}

Register this with Jackson Objectmapper:

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.ser.StdSerializerProvider;


public class CustomObjectMapper extends ObjectMapper{
    public CustomObjectMapper(){
        StdSerializerProvider sp = new StdSerializerProvider();
        sp.setNullValueSerializer(new NullSerializer());
        this.setSerializerProvider(sp);
    }

}

Register this objectmapper with Spring MVC:

<mvc:annotation-driven> 
   <mvc:message-converters register-defaults="true">
       <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
           <property name="objectMapper">
               <bean class="CustomObjectMapper"/>
           </property>
       </bean>
   </mvc:message-converters>
</mvc:annotation-driven>
2 of 2
0

I have also faced the same problem in my project and I have therefore quickly come up with a solution for the same. This post will surely help all those who have been struggling with the same issue.

Step 1:- Create your Custom Null Handler Serializer.

public class NullSerializer extends StdSerializer<Object> {

    public NullSerializer(Class<Object> t) {
       super(t);
    }

    public NullSerializer() {
      this(null);
    }

    @Override
    public void serialize(Object o, com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider serializerProvider) throws IOException {
       jsonGenerator.writeString("");
    }
   }

Step 2:- Create a bean of MappingJackson2HttpMessageConverter.

@Bean
@Primary
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {

    MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
    ObjectMapper mapper = new ObjectMapper();
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    mapper.getSerializerProvider().setNullValueSerializer(new NullSerializer());
    jsonConverter.setObjectMapper(mapper);
    return jsonConverter;

} 

Thank you for taking some time out to read this post. I hope that this was able to resolve your queries to some extent.

Top answer
1 of 2
2

I finally found what was my issue.

In my application, I use a custom RestTemplate. But this CustomRestTemplate use the default constructor of the Spring RestTemplate class. So it use the default MessageConverter list.

The solution was to add a constructor for my CustomRestTemplate with the MessageConverter list as input.

@Component
public class CustomRestTemplate extends RestTemplate {
    @Autowired
    public CustomRestTemplate (List<HttpMessageConverter<?>> messageConverters) {
        super(messageConverters);
    }
}

And to configuration the converter with the disabled "ACCEPT_EMPTY_STRING_AS_NULL_OBJECT" feature :

@Configuration
@ComponentScan(basePackages = "com.geodis.rt")
public class WebApplicationConfig extends WebMvcConfigurerAdapter {

    @Override
    public void configureMessageConverters( List<HttpMessageConverter<?>> converters ) {
        converters.add(0, converter());
    }

    @Bean
    MappingJackson2HttpMessageConverter converter() {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        converter.getObjectMapper().disable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
        return converter;
    }

}
2 of 2
1

Try disabling the ACCEPT_EMPTY_STRING_AS_NULL_OBJECT deserialization feature, but it should not be enabled by default so I would be surprised if this is the solution.

import com.fasterxml.jackson.databind.DeserializationFeature;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

@Configuration
public class JacksonConfiguration {

    @Bean
    public Jackson2ObjectMapperBuilder jacksonBuilder() {
        Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();

        builder.featuresToDisable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);

        return builder;
    }
}
🌐
Stack Overflow
stackoverflow.com › questions › 52090764 › can-anyone-tell-me-how-can-i-output-null-to-empty-values-using-jackson-mapper-in › 52091064
Can anyone tell me how can I output null to empty values using jackson mapper in spring Rest? - Stack Overflow
I don't want to change getter/setter method in every class to convert the null values to empty values. I am looking for a solution which will allow me to do this at global level using object mapper, by configuration perhaps. ... @Bean public Jackson2ObjectMapperBuilder configureObjectMapper() { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); ObjectMapper objectMapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.addSerializer(new NullSerializer()); objectMapper.registerModule(module); builder.configure(objectMapper); return builder; }
🌐
Baeldung
baeldung.com › home › json › jackson › jackson – working with maps and nulls
Jackson – Working With Maps and Nulls
May 2, 2023 - Now the Map with the null key will work just fine – and the null key will be written as an empty String:
🌐
Baeldung
baeldung.com › home › json › jackson › ignore null fields with jackson
Ignore Null Fields with Jackson | Baeldung
February 9, 2026 - In this tutorial, we look at how to ignore null values at the class level, the field level, and globally through the ObjectMapper. Jackson - Change the name of a field to adhere to a specific JSON format.
🌐
Java Guides
javaguides.net › 2019 › 04 › jackson-ignore-null-and-empty-fields-on-serialization.html
Jackson Ignore Null and Empty Fields on Serialization
April 24, 2019 - Jackson provides Include.NON_NULL to ignore fields with Null values and Include.NON_EMPTY to ignore fields with Empty values. By default, Jackson does not ignore Null and Empty fields while writing JSON.
🌐
Medium
medium.com › @umeshcapg › ignoring-null-fields-with-jackson-in-java-and-spring-boot-cc3ebb0acf99
Ignoring Null Fields with Jackson in Java and Spring Boot 🚀 | by Umesh Kumar Yadav | Medium
June 30, 2025 - Seasoned software developer with 12+ years of experience, specializing in Java, Spring Boot, Kafka, Redis, and system architecture. ... Null values are a common occurrence in software development, especially when dealing with incomplete or dynamic data. Properly handling nulls during serialization is critical to producing clean, efficient, and meaningful JSON outputs. Jackson, the de facto standard library for serializing and deserializing Java objects to and from JSON, offers robust mechanisms to ignore null fields during serialization.