Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hateoas.Link is not marked as ignorable #524

Closed
Rocks360 opened this issue Dec 10, 2016 · 4 comments
Closed

hateoas.Link is not marked as ignorable #524

Rocks360 opened this issue Dec 10, 2016 · 4 comments

Comments

@Rocks360
Copy link

Hello,
I get the following error when I try to consume a api with restTemplate

Sat Dec 10 17:11:23 CET 2016
There was an unexpected error (type=Bad Request, status=400).
Could not read document: Unrecognized field "templated" (class org.springframework.hateoas.Link), not marked as ignorable (one known property: "href"]) at [Source: java.io.PushbackInputStream@7a06aed1; line: 10, column: 25] (through reference chain: org.springframework.hateoas.Resource["_links"]->org.springframework.hateoas.Link["templated"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "templated" (class org.springframework.hateoas.Link), not marked as ignorable (one known property: "href"]) at [Source: java.io.PushbackInputStream@7a06aed1; line: 10, column: 25] (through reference chain: org.springframework.hateoas.Resource["_links"]->org.springframework.hateoas.Link["templated"])

I restTemplate request is the following:

ResponseEntity<Resource<Cart>> responseEntity = restTemplate.exchange(cartUrl, HttpMethod.GET, 
null, new ParameterizedTypeReference<Resource<Cart>>() {});

The response of the Rest api is the following:

{
  "creationDate": "2016-12-10T14:30:25.000+0000",
  "totalAmount": 501,
  "_links": {
    "self": {
      "href": "http://localhost:8082/carts/1"
    },
    "cart": {
      "href": "http://localhost:8082/carts/1{?projection}",
      "templated": true
    },
    "checkout": {
      "href": "http://localhost:8083/order"
    },
    "items": {
      "href": "http://localhost:8082/carts/1/items"
    }
  }
}

It already looked in the hateoas.Link class and the Annotation to ignore the "templated" property is already set but not recognized I guess.

@odrotbohm
Copy link
Member

Do you have your ObjectMapper configured to ignore unknown fields?

@Rocks360
Copy link
Author

Rocks360 commented Dec 12, 2016

Yes I did it like the following:

ObjectMapper objectMapper = new ObjectMapper(); 
		 objectMapper.registerModule(new Jackson2HalModule()); 
		 // todo: show if fix for Link property JsonIgnoreProperty templated is done
                 objectMapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false); 
		 //objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 

The FAIL_ON_IGNORED_PROPERTIES is default as false but I added it to make sure that no exeption is thrown if there is a value that should be explicit be ignored. If I comment that line out and use the below line it works. But the templated value is marked as ignorable so I'm wondering why it's not working without setting the FAIL_ON_UNKNOWN_PROPERTIES to false.

@odrotbohm
Copy link
Member

template is ignored, not isTemplated(). The latter cannot be ignored as it needs to render in responses obviously. The weirdness of that default in Jackson has been brought up with Jackson already. Also, Spring Boot actually reverts that, so if you consume a RestTemplate or ObjectMapper from the Spring ApplicationContext you're gonna get this set properly.

@Rocks360
Copy link
Author

Oh okay yes. Thank you for the answers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants