本文整理汇总了Java中com.fasterxml.jackson.databind.introspect.Annotated类的典型用法代码示例。如果您正苦于以下问题:Java Annotated类的具体用法?Java Annotated怎么用?Java Annotated使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Annotated类属于com.fasterxml.jackson.databind.introspect包,在下文中一共展示了Annotated类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObjectMapper
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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;
}
示例2: findSerializer
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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;
}
}
示例3: findDeserializer
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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;
}
}
示例4: findDeserializer
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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;
}
示例5: getObjectMapper
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
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;
}
示例6: findDeserializationConverter
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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));
}
示例7: findDeserializationConverter
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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));
}
示例8: setup
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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);
}
示例9: findNameForSerialization
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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;
}
示例10: findSerializationInclusion
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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;
}
示例11: findNameForDeserialization
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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;
}
示例12: createContextual
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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;
}
示例13: findSerializer
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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 );
}
示例14: findDeserializer
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
@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 );
}
示例15: getPropertyName
import com.fasterxml.jackson.databind.introspect.Annotated; //导入依赖的package包/类
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;
}