Hi Kent,
Thanks for your timely response..I had org.codehaus.jackson.jackson-mapper and org.codehaus.jackson.jackson-core(1.9.8). Currently downloading the databind jar and trying whether it works..When I further debugged the code, there's more dimension to this. My return class CustomeResponse is invoked by a customised HTTP Message Converter.
Code:
public class ConfigurableStringHttpMessageConverter extends AbstractHttpMessageConverter<Object>{
/** Logger */
private final static Logger logger = LoggerFactory
.getLogger(ConfigurableStringHttpMessageConverter.class);
private static final String CONST_TEXT ="text";
private static final String CONST_PLAIN ="plain";
private final List<Charset> availableCharsets;
private static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");
public ConfigurableStringHttpMessageConverter() {
this(DEFAULT_CHARSET);
}
public ConfigurableStringHttpMessageConverter(Charset defaultCharset) {
super(new MediaType("application", "json", defaultCharset));
MediaType mediaType = new MediaType("application", "json", defaultCharset);
List<MediaType> mediaTypes = new ArrayList<MediaType>();
mediaTypes.add(mediaType);
this.setSupportedMediaTypes(mediaTypes);
this.availableCharsets = new ArrayList<Charset>(Charset.availableCharsets().values());
}
@Override
public boolean supports(Class<? > clazz) {
return CustomResponse.class.isAssignableFrom(clazz);
}
@Override
protected String readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException,HttpMessageNotReadableException {
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET;
logger.debug("charset in READ {}",charset);
logger.debug("Content Type in READ {}",contentType);
return FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));
}
@Override
protected void writeInternal(Object s, HttpOutputMessage outputMessage) throws IOException {
outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
MediaType contentType = outputMessage.getHeaders().getContentType();
logger.debug("Content Type in WRITE {}",contentType);
Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET;
logger.debug("charset in WRITE {}",charset);
FileCopyUtils.copy(s.toString(), new OutputStreamWriter(outputMessage.getBody(), charset));
}
Dispatcher Servlet:
<bean class="com.apple.ist.gsx.util.WebAppBeanPostProcessor">
<property name="prependedMessageConvertors">
<list>
<bean id="configurableMessageConvertor" class="com.apple.ist.gsx.util.ConfigurableStringHttpMessageConverter">
<constructor-arg value="UTF-8"/>
</bean>
</list>
</property>
<property name="order" value="0"/>
</bean>
The customised HTTP message converter was done to enforce UTF-8 charset even for Japanese language..
Earlier it was setting content type to "text/plain". Now I tried explicilty setting the content type to application/json in the message converter as shown above..But it still doesn't work.
Thanks in advence,
Dinup.