java/jackson - chained @JsonValue annotations and deserialization
@JsonValue
is for serializing. The analogous annotation for deserializing is @JsonCreator
.
Annotate your constructors
@JsonCreator
public StringWrapper(final String s) {
this.s = s;
}
and
@JsonCreator
public StringWrapperOuter(final StringWrapper s) {
this.s = s;
}
As Sotirios said in a previous answer. The @JsonCreator
is the key here. But, in order to get all of the classes to work @JsonProperty
might be needed.
public static class POJO {
protected final List<StringWrapperOuter> data;
// In order for POJO creation to work properly the @JsonProperty
// annotation on the arg is required
@JsonCreator
public POJO(@JsonProperty("data") final List<StringWrapperOuter> data) {
this.data = data;
}
public List<StringWrapperOuter> getData() {
return data;
}
}
public static class StringWrapper {
protected final String s;
@JsonCreator
public StringWrapper(final String s) {
this.s = s;
}
@JsonValue
public String getS() {
return s;
}
}
public static class StringWrapperOuter {
protected final StringWrapper s;
@JsonCreator
public StringWrapperOuter(final StringWrapper s) {
this.s = s;
}
@JsonValue
public StringWrapper getS() {
return s;
}
}