From 1738688a98e74f67b80276fd6ab4a2982e8b6b55 Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Fri, 7 Dec 2018 11:30:53 -0600 Subject: [PATCH] #762 - Ignore unknown properties in LinkMixin. Ignore the "templated" property when deserializing HAL documents. Related pull requests: #668 Related issues: #667 --- .../hateoas/hal/LinkMixin.java | 4 ++-- .../hal/Jackson2HalIntegrationTest.java | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/hateoas/hal/LinkMixin.java b/src/main/java/org/springframework/hateoas/hal/LinkMixin.java index b7b9293c..dc96393a 100644 --- a/src/main/java/org/springframework/hateoas/hal/LinkMixin.java +++ b/src/main/java/org/springframework/hateoas/hal/LinkMixin.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; * @author Oliver Gierke * @author Greg Turnquist */ -@JsonIgnoreProperties({"rel", "media"}) +@JsonIgnoreProperties(value = {"rel", "media"}, ignoreUnknown = true) abstract class LinkMixin extends Link { private static final long serialVersionUID = 4720588561299667409L; diff --git a/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java b/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java index ac59acc6..8870d18c 100644 --- a/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.hateoas.hal; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -423,6 +424,27 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg assertThat(write(resourceSupport), is("{\"_links\":{\"self\":[{\"href\":\"localhost\"}]}}")); } + /** + * @see #667 + * @see #762 + */ + @Test + public void handleTemplatedLinksOnDeserialization() throws IOException { + + ResourceSupport original = new ResourceSupport(); + original.add(new Link("/orders{?id}", "order")); + + String serialized = mapper.writeValueAsString(original); + + String expected = "{\"_links\":{\"order\":{\"href\":\"/orders{?id}\",\"templated\":true}}}"; + + assertThat(serialized ,is(expected)); + + ResourceSupport deserialized = mapper.readValue(serialized, ResourceSupport.class); + + assertThat(deserialized, is(original)); + } + private static void verifyResolvedTitle(String resourceBundleKey) throws Exception { LocaleContextHolder.setLocale(Locale.US);