Java physical class sequence processing field does not return when NULL

tags: Java

    /**
     * Empty string back when the physical class sequence-field is NULL
     */
    @Configuration
    public class JacksonConfig {
        @Bean
        @Primary
        @ConditionalOnMissingBean(ObjectMapper.class)
        public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
            ObjectMapper objectMapper = builder.createXmlMapper(false).build();
            SerializerProvider serializerProvider = objectMapper.getSerializerProvider();
            serializerProvider.setNullValueSerializer(new JsonSerializer<Object>() {
                @Override
                public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
                    jsonGenerator.writeString("");
                }
            });
            return objectMapper;
        }
    }

Intelligent Recommendation

SpringBoot does not return null field methods

SpringBoot does not return Null field methods Add in the physical class @JsonInclude(JsonInclude.Include.NON_NULL) Example:...

Remember to query the return field as null processing as empty

I wanted to summarize this article very early, and today there is a similar needs, so move it out Foreword: When the back -end is tone with the front end, there is a situation that is like this. Can y...

[Java foundation actual combat] Java entity class: If a field is NULL, do not return this field (case detailed)

[Chen wants to work]: Hello Hello, I am Chen, I am very happy that you can read, nickname is hope that you can continue to enter, go to outstate programmer! The blog comes from the project and the que...

More Recommendation

When the backend data returns the front end, the field does not return NULL fields

content 1, require 2, [negligible] physical classes, interfaces, current effects, expected results Entity class interface Now effect expected result 3, realize Method 1: Application Configuration Meth...

When the Mybatis query uses the MAP return result, the null value field name does not display the problem

When the Mybatis query uses the MAP return result, the null value field name does not display the problem Just configure in Application.yml...

When the field type in the database does not match the Java entity type, mybatis will map the field to the physical attributes.

Project scene: Project scenario: When the field type in the database does not match the Java entity type, mybatis will map the field to the physical attribute Initial description For example, there is...

Customized Note - Determining if the physical class is null, restricting field length

We write interfaces to do the field must -fect checks and field length control, and front-end access will be converted with entity classes. In this way, the decision field can be determined whether th...

[JDK] Method to return null processing-Optional class

The main function of the Optional class is to deal with null. In the previous program development, to prevent null pointer exceptions in the program, null verification can be added. The party receivin...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top