3

We're trying to use a spring-cloud @FeignClient to call the HAL-JSON REST API of a microservice from another microservice. The service is implemented with Spring Data Rest, Spring Boot 1.4, with Hateoas enabled by default.

Using a dedicated DTO on the client side, all the simple properties are properly mapped, but the HAL-specific _embedded collection is ignored.

As taken primarly from this post, we implemented a custom Feign Decoder with a corresponding ObjectMapper, using the often mentioned Jackson2HalModule, but this still does not solve our issue.

You can reproduce the issue with this sample project, where the problem is described in more detail.

We appreciate any help or hints on this problem! Thanks in advance

Community
  • 1
  • 1
megli
  • 31
  • 6

2 Answers2

0

I think the key to understanding how to deserialize this is that your Customer is the Resources class that is embedding the relations. So you need to deserialize it as Resources in order for the HalResourcesDeserializer to pick it up.

I got it to work this way.

@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();
    }
}

This still looks a little odd and I am not sure if this is the best solution.

Mathias Dpunkt
  • 11,594
  • 4
  • 45
  • 70
0

I know I am responding to an old question, but in my experience, I had to add @EnableHyperMediaSupport to my main/any configuration class to resolve this issue. You can try that and verify if it works for you.

Prashant
  • 1,002
  • 13
  • 29
  • 1
    A more affirmative writing like 'You have to add ..... to....' will help to not confuse this answer as 'not an answer' – Steve Oct 28 '20 at 17:27
  • @Steve, Thank you for your feedback. When someone spends their time to show me how I could do better, I consider it a gift. I have modified my answer to incorporate your suggestion. – Prashant Oct 28 '20 at 18:01
  • 1
    I was telling you this because your answer has been caught by the BOT that looks for the 'not an answer' evidences. See https://chat.stackoverflow.com/transcript/message/50800235#50800235 We have already signalled this as a 'false positive' but still.... – Steve Oct 28 '20 at 18:09