我有一个返回Page<MyDto>
的端点。一切都很好,但在集成测试中,我收到了:
Type definition error: [simple type, class org.springframework.data.domain.Page]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.springframework.data.domain.Page` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 1]
feign.codec.DecodeException: Type definition error: [simple type, class org.springframework.data.domain.Page]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.springframework.data.domain.Page` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 1]
我看到了为PageImpl
添加包装器的解决方案,但我不想仅仅为了测试代码而创建包装器。还有其他简单的解决方案吗?
将以下配置添加到您的项目中:
@Configuration
public class FeignDecodeConfiguration {
@Bean
public Module pageJacksonModule() {
return new PageJacksonModule();
}
}
请参阅https://github.com/spring-cloud/spring-cloud-openfeign/issues/205了解更多详细信息。