Search in sources :

Example 1 with ArrayListOfMap

use of com.revolsys.collection.ArrayListOfMap in project com.revolsys.open by revolsys.

the class ListOfMapHttpMessageConverter method write.

@SuppressWarnings("unchecked")
@Override
public void write(final ArrayListOfMap list, final MediaType mediaType, final HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    if (!HttpServletUtils.getResponse().isCommitted()) {
        final Charset charset = HttpServletUtils.setContentTypeWithCharset(outputMessage, mediaType);
        final OutputStream body = outputMessage.getBody();
        final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
        final MapWriterFactory writerFactory = IoFactory.factoryByMediaType(MapWriterFactory.class, mediaTypeString);
        final MapWriter writer = writerFactory.newMapWriter(body, charset);
        writer.setProperty(IoConstants.INDENT, true);
        writer.setProperty(IoConstants.SINGLE_OBJECT_PROPERTY, false);
        final HttpServletRequest request = HttpServletUtils.getRequest();
        writer.setProperty(IoConstants.JSON_LIST_ROOT_PROPERTY, request.getAttribute(IoConstants.JSON_LIST_ROOT_PROPERTY));
        String callback = request.getParameter("jsonp");
        if (callback == null) {
            callback = request.getParameter("callback");
        }
        if (callback != null) {
            writer.setProperty(IoConstants.JSONP_PROPERTY, callback);
        }
        for (final Map<String, Object> map : (ArrayListOfMap<Object>) list) {
            writer.write(map);
        }
        writer.close();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MapWriter(com.revolsys.io.map.MapWriter) OutputStream(java.io.OutputStream) MapWriterFactory(com.revolsys.io.map.MapWriterFactory) ArrayListOfMap(com.revolsys.collection.ArrayListOfMap) Charset(java.nio.charset.Charset)

Aggregations

ArrayListOfMap (com.revolsys.collection.ArrayListOfMap)1 MapWriter (com.revolsys.io.map.MapWriter)1 MapWriterFactory (com.revolsys.io.map.MapWriterFactory)1 OutputStream (java.io.OutputStream)1 Charset (java.nio.charset.Charset)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1