2025-02-28 17:56:48 +08:00
|
|
|
|
package io.gisbi.jackson;
|
2025-02-27 14:44:08 +08:00
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
|
|
|
import com.fasterxml.jackson.core.StreamReadConstraints;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2025-05-22 16:34:14 +08:00
|
|
|
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
2025-02-27 14:44:08 +08:00
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
|
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
|
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
public class JacksonConfig {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
@Primary
|
|
|
|
|
@ConditionalOnMissingBean(ObjectMapper.class)
|
|
|
|
|
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
|
|
|
|
|
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
|
|
|
|
|
/*SimpleModule simpleModule = new SimpleModule();
|
|
|
|
|
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
|
|
|
|
objectMapper.registerModule(simpleModule);*/
|
|
|
|
|
objectMapper.setDefaultPropertyInclusion(JsonInclude.Include.ALWAYS);
|
|
|
|
|
return objectMapper;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-22 16:34:14 +08:00
|
|
|
|
@Bean
|
|
|
|
|
public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
|
|
|
|
|
return new Jackson2ObjectMapperBuilder()
|
|
|
|
|
.serializerByType(Long.TYPE, new ToStringSerializer())
|
|
|
|
|
.serializerByType(Long.class, new ToStringSerializer());
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-27 14:44:08 +08:00
|
|
|
|
@Bean
|
|
|
|
|
public Jackson2ObjectMapperBuilderCustomizer customJackson() {
|
|
|
|
|
return jacksonObjectMapperBuilder -> {
|
|
|
|
|
// 增大最大字符串长度限制到 350000000(或根据需要设置)
|
|
|
|
|
StreamReadConstraints constraints = StreamReadConstraints.builder()
|
|
|
|
|
.maxStringLength(35000000) // 设置更大的限制值
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
jacksonObjectMapperBuilder.postConfigurer(objectMapper ->
|
|
|
|
|
objectMapper.getFactory().setStreamReadConstraints(constraints)
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|