Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.analogweb.jackson;
 
 
org.analogweb.ResponseFormatter implementation for deserialise or serialise JSON with Jackson

Author(s):
snowgooseyk
public class JacksonJsonFormatter implements ResponseFormatter {
    private ObjectMapper mapper;
    protected ObjectMapper initObjectMapper() {
        ObjectMapper newMapper = new ObjectMapper();
        newMapper.configure(.false);
        return newMapper;
    }
    @Override
            String charsetfinal Object source) {
        final ObjectMapper mapper = getObjectMapper();
        return new ResponseEntity() {
            @Override
            public void writeInto(OutputStream responseBodythrows IOException {
                try {
                    mapper.writeValue(responseBodysource);
                } catch (IOException e) {
                    throw new FormatFailureException(esourcegetClass().getName());
                }
            }
            @Override
            public long getContentLength() {
                return -1;
            }
        };
    }
    protected ObjectMapper getObjectMapper() {
        if (this. == null) {
            this. = initObjectMapper();
        }
        return this.;
    }
    public synchronized void setObjectMapper(ObjectMapper mapper) {
        this. = mapper;
    }
New to GrepCode? Check out our FAQ X