In this case, if this works, you will eventually try to create the following:
{ "http://test.com" }
which is not legal JSON. @JsonUnwrapped really just removes one layer of wrapping. And although theoretically this can be done to work with arrays in arrays, this is not so. And actually, I am wondering if adding this function is a mistake: mainly because it encourages use, which is often associated with advanced data binding methods (simplicity, one-to-one mapping).
But instead, there will be @JsonValue :
@JsonValue private final List<URI> companies;
which means "use the value of this property instead of serializing the object that contains it."
And the creator method will work as is, it is not necessary for either @JsonUnwrapped or for @JsonProperty .
Here is the corrected code:
public static final class GetCompanies { private final List<URI> companies; @JsonCreator public GetCompanies(@NotNull List<URI> companies) { Preconditions.checkNotNull(companies, "companies"); this.companies = ImmutableList.copyOf(companies); } @JsonValue @SuppressWarnings("ReturnOfCollectionOrArrayField") public List<URI> getCompanies() { return companies; } }
Staxman
source share