protected String writeInternalAndReturnString(final Object o) throws MessageNotWritableException { final ByteArrayOutputStream out = writeInternal(o); return out.toString(); }
/** * Serialize the JSON content <code>json</code> into a Java object of type <code>clazz</code>. * * If <code>json</code> is either null or empty, returns an empty instance of type * <code>clazz</code> * * @param clazz * @param json * @return * @throws MessageNotReadableException */ protected Object readInternal(final Class<?> clazz, final String json) throws MessageNotReadableException { final JavaType javaType = getJavaType(clazz); try { if (StringUtils.hasText(json)) { return objectMapper.readValue(json, javaType); } else { return buildDefaultInstance(clazz); } } catch (final Exception e) { LOGGER.error("Error unmarshalling message {} into object of type {}", json, clazz.getName(), e); throw new MessageNotReadableException(e); } }
protected Object readInternal(final Class<?> clazz, final SentiloRequest request) throws JsonConverterException { try { return super.readInternal(clazz, request.getBody()); } catch (final Exception ex) { throw buildUnmarshallJsonException(clazz, ex); } }
protected void writeInternal(final Object obj, final SentiloResponse response) throws JsonConverterException { try { final ByteArrayOutputStream out = super.writeInternal(obj); response.setBody(out, DEFAULT_CONTENT_TYPE); } catch (final MessageNotWritableException ex) { throw buildMarshalJsonException(obj, ex); } }