@Override protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { Writer out = new OutputStreamWriter(outputMessage.getBody(), getCharset(outputMessage.getHeaders())); try { this.serializer.write(o, out); out.close(); } catch (Exception ex) { throw new HttpMessageNotWritableException("Could not write [" + o + "]", ex); } }
@Override protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { Reader source = new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders())); try { Object result = this.serializer.read(clazz, source); if (!clazz.isInstance(result)) { throw new TypeMismatchException(result, clazz); } return result; } catch (Exception ex) { throw new HttpMessageNotReadableException("Could not read [" + clazz + "]", ex); } }