I have the following class:
public class Message {
private String text;
public String getText() {
return text;
}
public void setText(St
On workaround: you don't absolutely need those getters/setters, so could just have:
public class MessageWrapper {
public Message message;
}
or perhaps add convenience constructor:
public class MessageWrapper {
public Message message;
@JsonCreator
public MessageWrapper(@JsonProperty("message") Message m) {
message = m;
}
}
There is a way to add wrapping too; with 1.9 you can use SerializationConfig.Feature.WRAP_ROOT_ELEMENT
and DeserializationConfig.Feature.UNWRAP_ROOT_ELEMENT
. And if you want to change the wrapper name (by default it is simply unqualified class name), you can use @JsonRootName
annotation
Jackson 2.0 adds further dynamic options via ObjectReader
and ObjectWriter
, as well as JAX-RS annotations.