Java Code Examples for com.fasterxml.jackson.databind.introspect.Annotated#getAnnotation()

The following examples show how to use com.fasterxml.jackson.databind.introspect.Annotated#getAnnotation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RosettaAnnotationIntrospector.java    From Rosetta with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public JsonSerializer<?> findSerializer(Annotated a) {
  StoredAsJson storedAsJson = a.getAnnotation(StoredAsJson.class);
  RosettaSerialize rosettaSerialize = a.getAnnotation(RosettaSerialize.class);
  if (storedAsJson != null && rosettaSerialize != null) {
    throw new IllegalArgumentException("Cannot have @StoredAsJson as well as @RosettaSerialize annotations on the same entry");
  }
  if (storedAsJson != null) {
    Class<?> type = a.getRawType();
    return storedAsJson.binary() ? new StoredAsJsonBinarySerializer(type) : new StoredAsJsonSerializer(type);
  }

  if (rosettaSerialize != null) {
    Class<? extends JsonSerializer> klass = rosettaSerialize.using();
    if (klass != JsonSerializer.None.class) {
      return ClassUtil.createInstance(
          klass,
          objectMapper.getSerializationConfig().canOverrideAccessModifiers());
    }
  }
  return null;
}
 
Example 2
Source File: SwaggerJacksonAnnotationIntrospector.java    From netty-rest with Apache License 2.0 6 votes vote down vote up
@Override
public List<NamedType> findSubtypes(Annotated a)
{
    final ApiModel api = a.getAnnotation(ApiModel.class);
    if (api != null) {
        final Class<?>[] classes = api.subTypes();
        final List<NamedType> names = new ArrayList<>(classes.length);
        for (Class<?> subType : classes) {
            names.add(new NamedType(subType));
        }
        if (!names.isEmpty()) {
            return names;
        }
    }

    return Collections.emptyList();
}
 
Example 3
Source File: JtModule.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Object findDeserializationConverter(Annotated a) {
    JtToMap ann = a.getAnnotation(JtToMap.class);
    if (ann == null) {
        return null;
    }
    JavaType javaType = a.getType();
    if(a instanceof AnnotatedMethod) {
        AnnotatedMethod am = (AnnotatedMethod) a;
        if(am.getParameterCount() == 1) {
            javaType = am.getParameterType(0);
        } else {
            throw new RuntimeException("Invalid property setter: " + am.getAnnotated());
        }
    }
    return new DeserializationConverterImpl(ann, new Ctx(a, javaType));
}
 
Example 4
Source File: SwaggerJacksonAnnotationIntrospector.java    From netty-rest with Apache License 2.0 6 votes vote down vote up
@Override
public String findPropertyDescription(Annotated a)
{
    ApiParam apiParam = a.getAnnotation(ApiParam.class);
    if (apiParam != null) {
        return apiParam.description();
    }

    ApiModel model = a.getAnnotation(ApiModel.class);
    if (model != null && !"".equals(model.description())) {
        return model.description();
    }
    ApiModelProperty prop = a.getAnnotation(ApiModelProperty.class);
    if (prop != null) {
        return prop.value();
    }
    return null;
}
 
Example 5
Source File: JSONAnnotationIntrospector.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
private PropertyName propertyName(Annotated annotated) {
    Property element = annotated.getAnnotation(Property.class);
    if (element != null) {
        return new PropertyName(element.name(), null);
    }
    return null;
}
 
Example 6
Source File: RosettaAnnotationIntrospector.java    From Rosetta with Apache License 2.0 5 votes vote down vote up
private PropertyName findRosettaPropertyName(Annotated a) {
  RosettaProperty ann = a.getAnnotation(RosettaProperty.class);
  if (ann != null) {
    return ann.value().isEmpty() ? PropertyName.USE_DEFAULT : new PropertyName(ann.value());
  }
  return null;
}
 
Example 7
Source File: RosettaAnnotationIntrospector.java    From Rosetta with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public JsonDeserializer<?> findDeserializer(Annotated a) {
  StoredAsJson storedAsJson = a.getAnnotation(StoredAsJson.class);
  RosettaDeserialize rosettaDeserialize = a.getAnnotation(RosettaDeserialize.class);
  if (storedAsJson != null && rosettaDeserialize != null) {
    throw new IllegalArgumentException("Cannot have @StoredAsJson as well as @RosettaDeserialize annotations on the same entry");
  }
  if (storedAsJson != null) {
    if (a instanceof AnnotatedMethod) {
      a = getAnnotatedTypeFromAnnotatedMethod((AnnotatedMethod) a);
    }

    String empty = StoredAsJson.NULL.equals(storedAsJson.empty()) ? "null" : storedAsJson.empty();
    return new StoredAsJsonDeserializer(a.getRawType(), getType(a), empty, objectMapper);
  }

  if (rosettaDeserialize != null) {
    Class<? extends JsonDeserializer> klass = rosettaDeserialize.using();
    if (klass != JsonDeserializer.None.class) {
      return ClassUtil.createInstance(
          klass,
          objectMapper.getDeserializationConfig().canOverrideAccessModifiers());
    }
  }

  return null;
}
 
Example 8
Source File: SwaggerJacksonAnnotationIntrospector.java    From netty-rest with Apache License 2.0 5 votes vote down vote up
@Override
public Integer findPropertyIndex(Annotated a)
{
    ApiModelProperty prop = a.getAnnotation(ApiModelProperty.class);
    if (prop != null && prop.position() != 0) {
        return prop.position();
    }
    return null;
}
 
Example 9
Source File: SwaggerJacksonAnnotationIntrospector.java    From netty-rest with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(Annotated a)
{
    ApiParam model = a.getAnnotation(ApiParam.class);
    if (model != null && !"".equals(model.value())) {
        return new PropertyName(model.value());
    }
    return null;
}
 
Example 10
Source File: SwaggerJacksonAnnotationIntrospector.java    From netty-rest with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForSerialization(Annotated a)
{
    ApiParam model = a.getAnnotation(ApiParam.class);
    if (model != null && !"".equals(model.value())) {
        return new PropertyName(model.value());
    }
    return null;
}
 
Example 11
Source File: Java7SupportImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean findTransient(Annotated a) {
    Transient t = a.getAnnotation(Transient.class);
    if (t != null) {
        return t.value();
    }
    return null;
}
 
Example 12
Source File: EntityAnnotationIntrospector.java    From requery with Apache License 2.0 5 votes vote down vote up
private PropertyName getMappedName(Annotated annotated) {
    if (annotated.hasAnnotation(Table.class)) {
        Table table = annotated.getAnnotation(Table.class);
        return new PropertyName(table.name());
    } if (annotated.hasAnnotation(View.class)) {
        View view = annotated.getAnnotation(View.class);
        return new PropertyName(view.name());
    } else if (annotated.hasAnnotation(Column.class)) {
        Column column = annotated.getAnnotation(Column.class);
        return new PropertyName(column.name());
    } else {
        return null;
    }
}
 
Example 13
Source File: KvSupportModule.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
private Class<? extends PropertyInterceptor>[] getInterceptors(Annotated a) {
    KvMapping ann = a.getAnnotation(KvMapping.class);
    if(ann == null) {
        return null;
    }
    Class<? extends PropertyInterceptor>[] interceptors = ann.interceptors();
    if(ArrayUtils.isEmpty(interceptors)) {
        return null;
    }
    return interceptors;
}
 
Example 14
Source File: JtModule.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Object findSerializationConverter(Annotated a) {
    JtToMap ann = a.getAnnotation(JtToMap.class);
    if (ann == null) {
        return null;
    }
    return new SerializationConverterImpl(ann, new Ctx(a, a.getType()));
}
 
Example 15
Source File: ApiAnnotationIntrospector.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForSerialization(Annotated a) {
  ApiResourceProperty apiName = a.getAnnotation(ApiResourceProperty.class);
  if (apiName != null && apiName.ignored() != AnnotationBoolean.TRUE) {
    return PropertyName.construct(apiName.name());
  }
  return null;
}
 
Example 16
Source File: Java7SupportImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean hasCreatorAnnotation(Annotated a) {
    ConstructorProperties props = a.getAnnotation(ConstructorProperties.class);
    // 08-Nov-2015, tatu: One possible check would be to ensure there is at least
    //    one name iff constructor has arguments. But seems unnecessary for now.
    if (props != null) {
        return Boolean.TRUE;
    }
    return null;
}
 
Example 17
Source File: ApiAnnotationIntrospector.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
private ApiResourceProperty findAnnotation(Annotated a) {
  ApiResourceProperty annotation = a.getAnnotation(ApiResourceProperty.class);
  return annotation != null && annotation.ignored() != AnnotationBoolean.TRUE ? annotation : null;
}
 
Example 18
Source File: SolrJacksonAnnotationInspector.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public String findPropertyDefaultValue(Annotated m) {
  JsonProperty prop = m.getAnnotation(JsonProperty.class);
  if (prop == null) return "";
  return prop.defaultValue();
}