Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.yammer.dropwizard.jersey;
  
 
A Jersey provider which enables using Jackson to parse request entities into objects and generate response entities from objects. Any request entity method parameters annotated with @Valid are validated, and an informative 422 Unprocessable Entity response is returned should the entity be invalid.

(Essentially, extends com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider with validation and support for com.fasterxml.jackson.annotation.JsonIgnoreType.)

 
 public class JacksonMessageBodyProvider extends JacksonJaxbJsonProvider {
    
The default group array used in case any of the validate methods is called without a group.
 
     private static final Class<?>[] DEFAULT_GROUP_ARRAY = new Class<?>[]{ Default.class };
     private final ObjectMapper mapper;
     private final Validator validator;
 
     public JacksonMessageBodyProvider(ObjectMapper mapperValidator validator) {
         this. = validator;
         this. = mapper;
         setMapper(mapper);
     }
 
     @Override
     public boolean isReadable(Class<?> type,
                               Type genericType,
                               Annotation[] annotations,
                               MediaType mediaType) {
         return isProvidable(type) && super.isReadable(typegenericTypeannotationsmediaType);
     }
 
     @Override
     public Object readFrom(Class<Objecttype,
                            Type genericType,
                            Annotation[] annotations,
                            MediaType mediaType,
                            MultivaluedMap<StringStringhttpHeaders,
                            InputStream entityStreamthrows IOException {
         return validate(annotationssuper.readFrom(type,
                                                     genericType,
                                                     annotations,
                                                     mediaType,
                                                     httpHeaders,
                                                     entityStream));
     }
 
     private Object validate(Annotation[] annotationsObject value) {
         final Class<?>[] classes = findValidationGroups(annotations);
 
         if (classes != null) {
             final ImmutableList<Stringerrors = .validate(valueclasses);
             if (!errors.isEmpty()) {
                 throw new InvalidEntityException("The request entity had the following errors:",
                                                  errors);
             }
         }
 
         return value;
     }
 
     private Class<?>[] findValidationGroups(Annotation[] annotations) {
         for (Annotation annotation : annotations) {
             if (annotation.annotationType() == Valid.class) {
                 return ;
             } else if (annotation.annotationType() == Validated.class) {
                 return  ((Validatedannotation).value();
             }
         }
         return null;
     }
 
     @Override
     public boolean isWriteable(Class<?> type,
                                Type genericType,
                                Annotation[] annotations,
                                MediaType mediaType) {
         return isProvidable(type) && super.isWriteable(typegenericTypeannotationsmediaType);
    }
    private boolean isProvidable(Class<?> type) {
        final JsonIgnoreType ignore = type.getAnnotation(JsonIgnoreType.class);
        return (ignore == null) || !ignore.value();
    }
    public ObjectMapper getObjectMapper() {
        return ;
    }
New to GrepCode? Check out our FAQ X