Example JSON (note that the string has trailing spaces):
{ \"aNumber\": 0, \"aString\": \"string \" }
Ideally, the deserialised instance
With a custom deserializer, you could do the following:
@JsonDeserialize(using=WhiteSpaceRemovalSerializer.class)
public void setAString(String aString) {
// body
}
public class WhiteSpaceRemovalDeserializer extends JsonDeserializer {
@Override
public String deserialize(JsonParser jp, DeserializationContext ctxt) {
// This is where you can deserialize your value the way you want.
// Don't know if the following expression is correct, this is just an idea.
return jp.getCurrentToken().asText().trim();
}
}
This solution does imply that this bean attribute will always be serialized this way, and you will have to annotate every attribute that you want to be deserialized this way.