Java 类com.fasterxml.jackson.databind.introspect.Annotated 实例源码
项目:eservice
文件:CommonBeans.java
@Bean(name = "objectMapper")
public ObjectMapper getObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new GuavaModule());
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JodaModule());
mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
// borrowed from: http://jackson-users.ning.com/forum/topics/how-to-not-include-type-info-during-serialization-with
@Override
protected TypeResolverBuilder<?> _findTypeResolver(MapperConfig<?> config, Annotated ann, JavaType baseType) {
// Don't serialize JsonTypeInfo Property includes
if (ann.hasAnnotation(JsonTypeInfo.class)
&& ann.getAnnotation(JsonTypeInfo.class).include() == JsonTypeInfo.As.PROPERTY
&& SerializationConfig.class.isAssignableFrom(config.getClass())) {
return null;
}
return super._findTypeResolver(config, ann, baseType);
}
});
return mapper;
}
项目:friendly-id
文件:FriendlyIdAnnotationIntrospector.java
@Override
public Object findSerializer(Annotated annotatedMethod) {
IdFormat annotation = annotatedMethod.getAnnotation(IdFormat.class);
if (annotatedMethod.getRawType() == UUID.class) {
if (annotation != null) {
switch (annotation.value()) {
case RAW:
return UUIDSerializer.class;
case URL62:
return FriendlyIdSerializer.class;
}
}
return FriendlyIdSerializer.class;
} else {
return null;
}
}
项目:friendly-id
文件:FriendlyIdAnnotationIntrospector.java
@Override
public Object findDeserializer(Annotated annotatedMethod) {
IdFormat annotation = annotatedMethod.getAnnotation(IdFormat.class);
if (rawDeserializationType(annotatedMethod) == UUID.class) {
if (annotation != null) {
switch (annotation.value()) {
case RAW:
return UUIDDeserializer.class;
case URL62:
return FriendlyIdDeserializer.class;
}
}
return FriendlyIdDeserializer.class;
} else {
return null;
}
}
项目:leopard
文件:DisablingJsonSerializerIntrospector.java
@Override
public Object findDeserializer(Annotated a) {
// System.err.println("Annotated:" + a.getClass().getName() + " " + a);
if (a instanceof AnnotatedClass) {
Class<?> clazz = ((AnnotatedClass) a).getAnnotated();
// System.err.println("clazz:" + clazz.getName() + " " + a.getName());
if (clazz.isEnum()) {
if (Onum.class.isAssignableFrom(clazz)) {
// System.err.println("OnumJsonSerializerIntrospector findDeserializer:" + clazz.getName() + " a:" + a);
return new OnumJsonDeserializer(clazz);
}
}
}
Object deserializer = super.findDeserializer(a);
return deserializer;
}
项目:factoryfx
文件:HttpServer.java
ObjectMapper getObjectMapper() {
ObjectMapper objectMapper = ObjectMapperBuilder.buildNewObjectMapper();
// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
SimpleModule module = new SimpleModule();
module.addSerializer(BigDecimal.class, new ToStringSerializer());
module.addSerializer(Long.class, new ToStringSerializer());
objectMapper.registerModule(module);
//Disable JsonIdentityInfo
JacksonAnnotationIntrospector ignoreJsonTypeInfoIntrospector = new JacksonAnnotationIntrospector() {
@Override
public ObjectIdInfo findObjectIdInfo(Annotated ann) {
return null;
}
};
objectMapper.setAnnotationIntrospector(ignoreJsonTypeInfoIntrospector);
return objectMapper;
}
项目:haven-platform
文件:JtModule.java
@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));
}
项目:haven-platform
文件:KvSupportModule.java
@Override
public Object findDeserializationConverter(Annotated a) {
Class<? extends PropertyInterceptor>[] interceptors = getInterceptors(a);
if (interceptors == 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 KvInterceptorsDeserializationConverter(interceptors, new KvPropertyContextImpl(a, javaType));
}
项目:bowman
文件:ResourceDeserializerTest.java
@Before
public void setup() {
typeResolver = mock(TypeResolver.class);
configuration = Configuration.build();
instantiator = mock(HandlerInstantiator.class);
doReturn(new ResourceDeserializer(Object.class, typeResolver, configuration))
.when(instantiator).deserializerInstance(any(DeserializationConfig.class),
any(Annotated.class), eq(ResourceDeserializer.class));
mapper = new ObjectMapper();
mapper.setHandlerInstantiator(instantiator);
mapper.registerModule(new Jackson2HalModule());
mapper.registerModule(new TestModule());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
项目:evt-bridge
文件:ElasticSearchAnnotationIntrospector.java
@Override
public PropertyName findNameForSerialization(Annotated a) {
if (!(a instanceof AnnotatedField) && !(a instanceof AnnotatedMethod)) {
return super.findNameForSerialization(a);
}
IndexableProperty property = a.getAnnotation(IndexableProperty.class);
if (property != null && !property.name().isEmpty()) {
return new PropertyName(property.name());
}
IndexableComponent component = a.getAnnotation(IndexableComponent.class);
if (component != null && !component.name().isEmpty()) {
return new PropertyName(component.name());
}
IndexableProperties properties = a.getAnnotation(IndexableProperties.class);
if (properties != null && !properties.name().isEmpty()) {
return new PropertyName(properties.name());
}
return PropertyName.USE_DEFAULT;
}
项目:evt-bridge
文件:ElasticSearchAnnotationIntrospector.java
@Override
public JsonInclude.Include findSerializationInclusion(Annotated a, JsonInclude.Include defValue) {
IndexableProperty property = a.getAnnotation(IndexableProperty.class);
if (property != null && property.jsonInclude() != com.github.aureliano.evtbridge.output.elasticsearch.enumeration.JsonInclude.DEFAULT) {
return JsonInclude.Include.valueOf(property.jsonInclude().toString());
}
IndexableComponent component = a.getAnnotation(IndexableComponent.class);
if (component != null && component.jsonInclude() != com.github.aureliano.evtbridge.output.elasticsearch.enumeration.JsonInclude.DEFAULT) {
return JsonInclude.Include.valueOf(component.jsonInclude().toString());
}
IndexableProperties properties = a.getAnnotation(IndexableProperties.class);
if (properties != null && properties.jsonInclude() != com.github.aureliano.evtbridge.output.elasticsearch.enumeration.JsonInclude.DEFAULT) {
return JsonInclude.Include.valueOf(properties.jsonInclude().toString());
}
return defValue;
}
项目:evt-bridge
文件:ElasticSearchAnnotationIntrospector.java
@Override
public PropertyName findNameForDeserialization(Annotated a) {
if (!(a instanceof AnnotatedField) && !(a instanceof AnnotatedMethod)) {
return super.findNameForDeserialization(a);
}
IndexableProperty property = a.getAnnotation(IndexableProperty.class);
if (property != null && !property.name().isEmpty()) {
return new PropertyName(property.name());
}
IndexableComponent component = a.getAnnotation(IndexableComponent.class);
if (component != null && !component.name().isEmpty()) {
return new PropertyName(component.name());
}
IndexableProperties properties = a.getAnnotation(IndexableProperties.class);
if (properties != null && !properties.name().isEmpty()) {
return new PropertyName(properties.name());
}
return PropertyName.USE_DEFAULT;
}
项目:bootique
文件:JSR310DateTimeDeserializerBase.java
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException {
if (property != null) {
JsonFormat.Value format = ctxt.getAnnotationIntrospector().findFormat((Annotated) property.getMember());
if (format != null) {
if (format.hasPattern()) {
final String pattern = format.getPattern();
final Locale locale = format.hasLocale() ? format.getLocale() : ctxt.getLocale();
DateTimeFormatter df;
if (locale == null) {
df = DateTimeFormatter.ofPattern(pattern);
} else {
df = DateTimeFormatter.ofPattern(pattern, locale);
}
return withDateFormat(df);
}
// any use for TimeZone?
}
}
return this;
}
项目:NyBatisCore
文件:ColumnAnnotationInspector.java
@Override
public Object findSerializer( Annotated annotated ) {
if( ! annotated.hasAnnotation(Column.class) || ! isStringType(annotated) ) {
return super.findSerializer( annotated );
}
Class classType = annotated.getRawType();
if( Types.isNotString(classType) ) {
if( Types.isBoolean(classType) ) {
return ColumnBooleanSerializer.class;
} else if( ! Types.isPrimitive(classType) ) {
return ColumnBeanSerializer.class;
}
}
return super.findSerializer( annotated );
}
项目:NyBatisCore
文件:ColumnAnnotationInspector.java
@Override
public Object findDeserializer( Annotated annotated ) {
if( ! annotated.hasAnnotation(Column.class) || ! isStringType(annotated) ) {
return super.findDeserializer( annotated );
}
Class classType;
try {
classType = ( (AnnotatedMethod) annotated ).getRawParameterType( 0 );
} catch( Exception e ) {
classType = annotated.getRawType();
}
if( Types.isNotString(classType) ) {
if( Types.isBoolean(classType) ) {
return ColumnBooleanDeserializer.class;
} else if( ! Types.isPrimitive(classType) ) {
return ColumnBeanDeserializer.class;
}
}
return super.findDeserializer( annotated );
}
项目:NyBatisCore
文件:ColumnAnnotationInspector.java
private PropertyName getPropertyName( Annotated annotated ) {
Column column = annotated.getAnnotation( Column.class );
if ( column != null && StringUtil.isNotEmpty(annotated.getName()) ) {
String name = column.name();
name = StringUtil.toUncamel( name );
name = StringUtil.toCamel( name );
return new PropertyName( name );
}
JsonProperty jsonProperty = annotated.getAnnotation( JsonProperty.class );
if( jsonProperty != null ) {
if( StringUtil.isNotEmpty(jsonProperty.value()) ) {
return new PropertyName( jsonProperty.value() );
} else {
return PropertyName.USE_DEFAULT;
}
}
return null;
}
项目:netty-rest
文件:SwaggerJacksonAnnotationIntrospector.java
@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;
}
项目:netty-rest
文件:SwaggerJacksonAnnotationIntrospector.java
@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();
}
项目:QuizUpWinner
文件:BasicDeserializerFactory.java
public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig paramDeserializationConfig, Annotated paramAnnotated, Object paramObject)
{
if (paramObject == null)
return null;
if ((paramObject instanceof ValueInstantiator))
return (ValueInstantiator)paramObject;
if (!(paramObject instanceof Class))
throw new IllegalStateException("AnnotationIntrospector returned key deserializer definition of type " + paramObject.getClass().getName() + "; expected type KeyDeserializer or Class<KeyDeserializer> instead");
Class localClass = (Class)paramObject;
if (localClass == NoClass.class)
return null;
if (!ValueInstantiator.class.isAssignableFrom(localClass))
throw new IllegalStateException("AnnotationIntrospector returned Class " + localClass.getName() + "; expected Class<ValueInstantiator>");
HandlerInstantiator localHandlerInstantiator = paramDeserializationConfig.getHandlerInstantiator();
if (localHandlerInstantiator != null)
{
ValueInstantiator localValueInstantiator = localHandlerInstantiator.valueInstantiatorInstance(paramDeserializationConfig, paramAnnotated, localClass);
if (localValueInstantiator != null)
return localValueInstantiator;
}
return (ValueInstantiator)ClassUtil.createInstance(localClass, paramDeserializationConfig.canOverrideAccessModifiers());
}
项目:QuizUpWinner
文件:AnnotationIntrospector.java
public PropertyName findNameForDeserialization(Annotated paramAnnotated)
{
String str;
if ((paramAnnotated instanceof AnnotatedField))
str = findDeserializationName((AnnotatedField)paramAnnotated);
else if ((paramAnnotated instanceof AnnotatedMethod))
str = findDeserializationName((AnnotatedMethod)paramAnnotated);
else if ((paramAnnotated instanceof AnnotatedParameter))
str = findDeserializationName((AnnotatedParameter)paramAnnotated);
else
str = null;
if (str != null)
{
if (str.length() == 0)
return PropertyName.USE_DEFAULT;
return new PropertyName(str);
}
return null;
}
项目:QuizUpWinner
文件:AnnotationIntrospector.java
public PropertyName findNameForSerialization(Annotated paramAnnotated)
{
String str;
if ((paramAnnotated instanceof AnnotatedField))
str = findSerializationName((AnnotatedField)paramAnnotated);
else if ((paramAnnotated instanceof AnnotatedMethod))
str = findSerializationName((AnnotatedMethod)paramAnnotated);
else
str = null;
if (str != null)
{
if (str.length() == 0)
return PropertyName.USE_DEFAULT;
return new PropertyName(str);
}
return null;
}
项目:kansalaisaloite
文件:JsonIdAnnotationIntrospector.java
@Override
public Object findSerializer(Annotated a) {
final JsonId ann = a.getAnnotation(JsonId.class);
if (ann != null) {
return new JsonSerializer<Long>() {
@Override
public void serialize(Long value, JsonGenerator jgen,
SerializerProvider provider) throws IOException,
JsonProcessingException {
jgen.writeString(baseUrl + ann.path().replace("{id}", value.toString()));
}
};
} else {
return super.findSerializer(a);
}
}
项目:jackson-lombok
文件:JacksonLombokAnnotationIntrospector.java
@Override
public boolean hasCreatorAnnotation(Annotated annotated) {
if (super.hasCreatorAnnotation(annotated)) {
return true;
} else if (!(annotated instanceof AnnotatedConstructor)) {
return false;
} else {
AnnotatedConstructor annotatedConstructor = (AnnotatedConstructor) annotated;
ConstructorProperties properties = getConstructorPropertiesAnnotation(annotatedConstructor);
if (properties == null) {
return false;
} else {
addJacksonAnnotationsToContructorParameters(annotatedConstructor);
return true;
}
}
}
项目:hypersocket-framework
文件:MigrationHandlerInstantiator.java
@Override
public JsonDeserializer<?> deserializerInstance(DeserializationConfig config, Annotated annotated, Class<?> deserClass) {
try{
if(MigrationDeserializer.class.equals(deserClass)) {
return migrationDeserializer;
} else if(None.class.equals(deserClass)) {
return null;
}
System.out.println("DeserializationConfig " + config);
System.out.println("Annotated " + annotated);
System.out.println("deserClass Class<?> " + deserClass);
return (JsonDeserializer<?>) deserClass.newInstance();
}catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
项目:codec
文件:CodecIntrospector.java
/** report all non-alias plugin types */
@Override
public List<NamedType> findSubtypes(Annotated a) {
Pluggable pluggable = a.getAnnotation(Pluggable.class);
PluginMap pluginMap;
if (pluggable != null) {
pluginMap = pluginRegistry.byCategory().get(pluggable.value());
} else if (pluginRegistry.byClass().containsKey(a.getRawType())) {
pluginMap = pluginRegistry.byClass().get(a.getRawType());
} else {
return null;
}
List<NamedType> result = new ArrayList<>(pluginMap.asBiMap().size());
for (Map.Entry<String, Class<?>> type : pluginMap.asBiMap().entrySet()) {
result.add(new NamedType(type.getValue(), type.getKey()));
}
return result;
}
项目:cloudstack
文件:CSJacksonAnnotationIntrospector.java
@Override
public Object findSerializer(Annotated a) {
AnnotatedElement ae = a.getAnnotated();
Url an = ae.getAnnotation(Url.class);
if (an == null) {
return null;
}
if (an.type() == String.class) {
return new UriSerializer(an);
} else if (an.type() == List.class) {
return new UrisSerializer(an);
}
throw new UnsupportedOperationException("Unsupported type " + an.type());
}
项目:joyplus-tv
文件:DefaultSerializerProvider.java
@Override
public ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated,
ObjectIdInfo objectIdInfo)
throws JsonMappingException
{
Class<?> implClass = objectIdInfo.getGeneratorType();
HandlerInstantiator hi = _config.getHandlerInstantiator();
ObjectIdGenerator<?> gen;
if (hi != null) {
gen = hi.objectIdGeneratorInstance(_config, annotated, implClass);
} else {
gen = (ObjectIdGenerator<?>) ClassUtil.createInstance(implClass,
_config.canOverrideAccessModifiers());
}
return gen.forScope(objectIdInfo.getScope());
}
项目:joyplus-tv
文件:DefaultDeserializationContext.java
@Override
public ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated,
ObjectIdInfo objectIdInfo)
throws JsonMappingException
{
Class<?> implClass = objectIdInfo.getGeneratorType();
HandlerInstantiator hi = _config.getHandlerInstantiator();
ObjectIdGenerator<?> gen;
if (hi != null) {
gen = hi.objectIdGeneratorInstance(_config, annotated, implClass);
} else {
gen = (ObjectIdGenerator<?>) ClassUtil.createInstance(implClass,
_config.canOverrideAccessModifiers());
}
return gen.forScope(objectIdInfo.getScope());
}
项目:buildhealth
文件:BuildHealthWebServer.java
private String getName(Annotated ann) {
AnnotatedElement element = ann.getAnnotated();
if (element instanceof Field)
return ((Field) element).getName();
if (element instanceof java.lang.reflect.Method) {
String name = ((java.lang.reflect.Method) element).getName();
if (name.startsWith("is"))
name = name.substring(2);
if (name.startsWith("get"))
name = name.substring(3);
if (name.length() < 2)
return name;
return name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1);
}
return null;
}
项目:qpp-conversion-tool
文件:JsonWrapper.java
/**
* Apply the {@link JsonWrapperIntrospector#filterName} filter to all instances of Map.
*
* @param a objects to be serialized
* @return either the specified filter or a the default supplied by the parent.
* @see JacksonAnnotationIntrospector
*/
@Override
public Object findFilterId(Annotated a) {
if (Map.class.isAssignableFrom(a.getRawType())) {
return filterName;
}
return super.findFilterId(a);
}
项目:ARCLib
文件:ObjectMapperProducer.java
@Override
public Object findFilterId(Annotated a) {
Object id = super.findFilterId(a);
if (id == null) {
id = JAVASSIST_FILTER_ID;
}
return id;
}
项目:ARCLib
文件:Gatherer.java
@Override
public Object findFilterId(Annotated a) {
Object id = super.findFilterId(a);
if (id == null) {
id = CGLIB_FILTER_ID;
}
return id;
}
项目:koryphe
文件:DelegatingAnnotationIntrospector.java
@SuppressFBWarnings(value = "SIC_INNER_SHOULD_BE_STATIC_ANON", justification = "This is required")
@SuppressWarnings("unchecked")
@Override
protected <A extends Annotation> A _findAnnotation(
final Annotated annotated, final Class<A> annoClass) {
A annotation = super._findAnnotation(annotated, annoClass);
if (null == annotation) {
annotation = (A) delegateAnnotations.get(annoClass);
}
return annotation;
}
项目:gitplex-mit
文件:HibernateAnnotationIntrospector.java
@SuppressWarnings("unchecked")
@Override
public Object findSerializer(Annotated am) {
if (am.hasAnnotation(ManyToOne.class)) {
return new ManyToOneSerializer((Class<AbstractEntity>) am.getRawType());
} else {
return super.findDeserializer(am);
}
}
项目:gitplex-mit
文件:HibernateAnnotationIntrospector.java
@Override
public Object findDeserializer(Annotated am) {
if (am.hasAnnotation(ManyToOne.class)) {
return new ManyToOneDeserializer(am.getRawType());
} else {
return super.findDeserializer(am);
}
}
项目:power-jambda
文件:MaskableSensitiveDataAnnotationIntrospector.java
@Override
public Object findSerializer(Annotated am) {
MaskableSensitiveData annotation = am.getAnnotation(MaskableSensitiveData.class);
if (annotation != null) {
return MaskableSerializerFactory.createSerializer(am.getType(), annotation);
}
return null;
}
项目:friendly-id
文件:FriendlyIdAnnotationIntrospector.java
protected Class<?> rawDeserializationType(Annotated a) {
if (a instanceof AnnotatedMethod) {
AnnotatedMethod am = (AnnotatedMethod) a;
if (am.getParameterCount() == 1) {
return am.getRawParameterType(0);
}
}
return a.getRawType();
}
项目:Mastering-Mesos
文件:ObfuscateAnnotationIntrospector.java
@Override
public Object findSerializer(Annotated am) {
if (am.hasAnnotation(Obfuscate.class)) {
return OBFUSCATE_SERIALIZER;
} else {
return null;
}
}
项目:leopard
文件:DisablingJsonSerializerIntrospector.java
@Override
public Object findSerializer(Annotated am) {
// System.err.println("am:" + am.getName());
return null;
// Object serializer = super.findSerializer(am);
// if (serializer != null) {
// Class<?> clazz = (Class<?>) serializer;
// String className = clazz.getName();
// if (className.endsWith("ProvinceJsonSerializer")) {
// return null;
// }
// }
// return serializer;
}
项目:mblog
文件:JsonUtils.java
@Override
public Object findSerializer(Annotated a) {
if (a instanceof AnnotatedMethod) {
AnnotatedElement m = a.getAnnotated();
DateTimeFormat an = m.getAnnotation(DateTimeFormat.class);
if (an != null) {
if (!DEFAULT_DATE_FORMAT.equals(an.pattern())) {
return new JsonDateSerializer(an.pattern());
}
}
}
return super.findSerializer(a);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ConfigurationPropertiesReportEndpoint.java
@Override
public Object findFilterId(Annotated a) {
Object id = super.findFilterId(a);
if (id == null) {
id = CGLIB_FILTER_ID;
}
return id;
}