在增加了 JtsModule 之后,Spring Boot 项目输出的 rest 接口对于 Geometry 的对象 序列化成 json 依然报错:
com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain:
org.locationtech.jts.geom.Point["envelope"]->.........
但是已经引入了 JtsModule
implementation group: 'org.n52.jackson', name: 'jackson-datatype-jts', version: '1.2.10'
并且配置了 jackson
@Bean
@Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build()
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
.registerModule(new JtsModule());
return objectMapper;
}
依然报错,问题出在
@SpringBootApplication
@EnableWebMvc // 这个开启会影响 自定义的 jackson mapper bean .
public class GridApp {
public static void main(String[] args) {
SpringApplication.run(GridApp.class,args);
}
}
解除办法
// 移除 @EnableWebMvc 注解