DATACMNS-885 - Workaround for bug in Jayway's JSONPath array access.

When a recursive decent operator is used in a JSON Path expression there's no way to get out of the array mode again to indicate one is interested in a particular element (e.g. "the first one no matter where in the document") [0]. We now work around this by always letting the parser return lists, so that the mapping library finally kicking in can be equipped with the correct target type to create.

Unfortunately this causes arrays to be double-wrapped for definite paths so that we basically have to adapt the type handed to Jackson in another round to the unwrap the mapping result in turn [1].

[0] https://github.com/jayway/JsonPath/issues/248
[1] https://github.com/jayway/JsonPath/issues/249
This commit is contained in:
Oliver Gierke
2016-07-18 12:32:59 +02:00
parent eec2b43fd0
commit 762a12b4a2
2 changed files with 38 additions and 2 deletions

View File

@@ -163,6 +163,16 @@ public class JsonProjectingMethodInterceptorFactoryUnitTests {
assertThat(name.getFirstname(), is("Dave"));
}
/**
* @see DATACMNS-885
*/
@Test
public void accessNestedFields() {
assertThat(customer.getNestedCity(), is("Dresden"));
assertThat(customer.getNestedCities(), hasSize(2));
}
interface Customer {
String getFirstname();
@@ -194,6 +204,12 @@ public class JsonProjectingMethodInterceptorFactoryUnitTests {
@JsonPath("$.address")
Set<AnotherAddressProjection> getAnotherAddressProjectionAsCollection();
@JsonPath("$..city")
String getNestedCity();
@JsonPath("$..city")
List<String> getNestedCities();
}
interface AddressProjection {