@Override public void writeTo(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { if (!supportSimpleTypesOnly && !InjectionUtils.isPrimitive(type)) { @SuppressWarnings("unchecked") MessageBodyWriter<T> next = (MessageBodyWriter<T>)providers.getMessageBodyWriter(type, genericType, annotations, mediaType); JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this); try { next.writeTo(t, type, genericType, annotations, mediaType, headers, os); } finally { JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null); } } else { os.write(StringUtils.toBytesASCII("{\"" + type.getSimpleName().toLowerCase() + "\":")); writeQuote(os, type); primitiveHelper.writeTo(t, type, genericType, annotations, mediaType, headers, os); writeQuote(os, type); os.write(StringUtils.toBytesASCII("}")); } }
@Override public void writeTo(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { if (!supportSimpleTypesOnly && !InjectionUtils.isPrimitive(type)) { @SuppressWarnings("unchecked") MessageBodyWriter<T> next = (MessageBodyWriter<T>)providers.getMessageBodyWriter(type, genericType, annotations, mediaType); JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this); try { next.writeTo(t, type, genericType, annotations, mediaType, headers, os); } finally { JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null); } } else { os.write(StringUtils.toBytesASCII("{\"" + type.getSimpleName().toLowerCase() + "\":")); writeQuote(os, type); primitiveHelper.writeTo(t, type, genericType, annotations, mediaType, headers, os); writeQuote(os, type); os.write(StringUtils.toBytesASCII("}")); } }