Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.analogweb.jackson;
 
 import java.io.Reader;
 
org.analogweb.core.SpecificMediaTypeRequestValueResolver implementation for Jackson. Parse JSON formatted request body using Jackson's com.fasterxml.jackson.databind.ObjectMapper.

Author(s):
snowgoose
    private ObjectMapper mapper;
    protected ObjectMapper initObjectMapper() {
        ObjectMapper newMapper = new ObjectMapper();
        return newMapper;
    }
    @Override
    public Object resolveValue(RequestContext contextInvocationMetadata metadataString key,
            Class<?> requiredTypeAnnotation[] annotations) {
        try {
            return jsonToObject(context.getRequestBody(), requiredType);
        } catch (IOException e) {
            throw new InvalidRequestFormatException(egetClass());
        }
    }
    protected Object jsonToObject(InputStream inClass<?> requiredType) {
        try {
            return getObjectMapper().readValue(inrequiredType);
        } catch (JsonMappingException e) {
            throw new ApplicationRuntimeException(e) {
                private static final long serialVersionUID = 1L;
            };
        } catch (JsonParseException e) {
            throw new InvalidRequestFormatException(eJacksonJsonValueResolver.class);
        } catch (IOException e){
            throw new InvalidRequestFormatException(egetClass());
        }
    }
    protected Object jsonToObject(Reader readerClass<?> requiredType) {
        try {
            return getObjectMapper().readValue(readerrequiredType);
        } catch (JsonMappingException e) {
            throw new InvalidRequestFormatException(egetClass());
        } catch (JsonParseException e) {
            throw new InvalidRequestFormatException(egetClass());
        } catch (IOException e){
            throw new InvalidRequestFormatException(egetClass());
        }
    }
    @Override
    public boolean supports(MediaType mediaType) {
        return ..isCompatible(mediaType);
    }
    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