如何使用@FeignClient映射HAL JSON _embedded集合
问题描述:
我们试图使用spring-cloud @FeignClient
从另一个微服务调用微服务的HAL-JSON REST API。该服务使用Spring Data Rest,Spring Boot 1.4实现,缺省情况下启用Hateoas。如何使用@FeignClient映射HAL JSON _embedded集合
在客户端使用专用的DTO,所有简单属性都被正确映射,但HAL特定的_embedded
集合被忽略。
由于从this post primarly拍摄,我们实现了一个自定义的假死Decoder
与相应ObjectMapper
,使用经常提到Jackson2HalModule
,但是这仍然没有解决我们的问题。
您可以使用this sample project重现问题,其中更详细地描述了问题。
感谢您对此问题的任何帮助或提示!在此先感谢
答
我认为理解如何反序列化的关键是你的Customer
是嵌入关系的Resources
类。因此,您需要将其反序列化为Resources
,以便HalResourcesDeserializer
可以将其取出。
我是这样工作的。
@Getter
@Setter
public class Customer extends Resources<Resource<Relation>> {
public static enum Type {
PERSON, INSTITUTION
}
private String displayName;
private Integer rating;
private Type type;
public Collection<Resource<Relation>> getRelations() {
return this.getContent();
}
}
这仍然看起来有点奇怪,我不知道这是否是最好的解决方案。
@megli有帮助吗? –