File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
main/java/org/springframework/hateoas
test/java/org/springframework/hateoas/hal Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -207,14 +207,26 @@ public List<TemplateVariable> getVariables() {
207
207
}
208
208
209
209
/**
210
- * Returns whether the link is templated.
210
+ * Returns whether or not the link is templated.
211
211
*
212
212
* @return
213
213
*/
214
214
public boolean isTemplated () {
215
215
return !getUriTemplate ().getVariables ().isEmpty ();
216
216
}
217
217
218
+ /**
219
+ * This no-op setter is required to deserialize a link that contains a templated URL. It allows Jackson to
220
+ * "set" the property, but since {@code templated} is a virtual property, the injected value {@code true} or
221
+ * {@code false) is ignored.
222
+ *
223
+ * The method is kept private so no one attempts to actually use it.
224
+ *
225
+ * @param __ - don't care what value is passed in. The true value {@link #isTemplated()} is based upon the {@link UriTemplate}.
226
+ */
227
+ private void setTemplated (boolean __ ) {
228
+ }
229
+
218
230
/**
219
231
* Turns the current template into a {@link Link} by expanding it using the given parameters.
220
232
*
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2012-2017 the original author or authors.
2
+ * Copyright 2012-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
18
18
import static org .assertj .core .api .Assertions .*;
19
19
20
+ import java .io .IOException ;
20
21
import java .util .ArrayList ;
21
22
import java .util .Arrays ;
22
23
import java .util .Collection ;
@@ -453,6 +454,26 @@ public void rendersSingleLinkAsArrayWhenConfigured() throws Exception {
453
454
assertThat (write (resourceSupport )).isEqualTo ("{\" _links\" :{\" self\" :[{\" href\" :\" localhost\" }]}}" );
454
455
}
455
456
457
+ /**
458
+ * @see #667
459
+ */
460
+ @ Test
461
+ public void handleTemplatedLinksOnDeserialization () throws IOException {
462
+
463
+ ResourceSupport original = new ResourceSupport ();
464
+ original .add (new Link ("/orders{?id}" , "order" ));
465
+
466
+ String serialized = mapper .writeValueAsString (original );
467
+
468
+ String expected = "{\" _links\" :{\" order\" :{\" href\" :\" /orders{?id}\" ,\" templated\" :true}}}" ;
469
+
470
+ assertThat (serialized ).isEqualTo (expected );
471
+
472
+ ResourceSupport deserialized = mapper .readValue (serialized , ResourceSupport .class );
473
+
474
+ assertThat (deserialized ).isEqualTo (original );
475
+ }
476
+
456
477
private static void verifyResolvedTitle (String resourceBundleKey ) throws Exception {
457
478
458
479
LocaleContextHolder .setLocale (Locale .US );
You can’t perform that action at this time.
0 commit comments