Ok, I went back and looked at how I did this in the past. Again, I was using Spring. For my case, I wanted to trim off the leading and trailing whitespace from all my inputs. Here's how I did it.
In the spring xml config, I have
<!-- Configures the @Controller model -->
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters>
<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="prefixJson" value="false"/>
<property name="supportedMediaTypes" value="application/json"/>
<property name="objectMapper" ref="customObjectMapper"></property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<bean id="customObjectMapper" class="com.domain.json.CustomObjectMapper"/>
Here's the CustomObjectMapper class
public class CustomObjectMapper extends ObjectMapper
{
private static final long serialVersionUID = 1L;
public CustomObjectMapper()
{
registerModule(new StringMapperModule());
}
}
And finally the StringMapperModule class
public class StringMapperModule extends SimpleModule
{
private static final long serialVersionUID = 1L;
/**
* Modify json data globally
*/
public StringMapperModule()
{
super();
addDeserializer(String.class, new StdScalarDeserializer<String>(String.class)
{
private static final long serialVersionUID = 1L;
@Override
public String deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException
{
// remove leading and trailing whitespace
return StringUtils.trim(jp.getValueAsString());
}
});
}
}
I hope you find this helpful or that it at leasts points you in the right direction.