解决jackson反序列化抽象类属性时报错

时间:2025-03-27 17:17:37
@Configuration public class JsonConfig { @Bean public ObjectMapper getJacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { ObjectMapper objectMapper = builder.createXmlMapper(false).build(); SimpleModule simpleModule = new SimpleModule(); SimpleAbstractTypeResolver simpleAbstractTypeResolver = new SimpleAbstractTypeResolver(); // 添加接口映射子类 simpleAbstractTypeResolver.addMapping(DoudianOpClient.class, DefaultDoudianOpClient.class); simpleModule.setAbstractTypes(simpleAbstractTypeResolver); objectMapper.registerModule(simpleModule); return objectMapper; } }