本文整理汇总了Java中com.fasterxml.jackson.databind.BeanDescription类的典型用法代码示例。如果您正苦于以下问题:Java BeanDescription类的具体用法?Java BeanDescription怎么用?Java BeanDescription使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BeanDescription类属于com.fasterxml.jackson.databind包,在下文中一共展示了BeanDescription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupModule
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@Override
public void setupModule(SetupContext setupContext) {
super.setupModule(setupContext);
setupContext.addBeanSerializerModifier(new BeanSerializerModifier() {
@SuppressWarnings("unchecked")
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig serializationConfig, BeanDescription beanDescription, JsonSerializer<?> jsonSerializer) {
Class<?> beanClass = beanDescription.getBeanClass();
if (Cause.class.isAssignableFrom(beanClass)) {
return new CauseSerializer((JsonSerializer<Object>) jsonSerializer);
} else if (StackTraceElement.class.isAssignableFrom(beanClass)) {
return new StackTraceElementSerializer();
}
return jsonSerializer;
}
});
}
示例2: setupModule
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@Override
public void setupModule(final SetupContext context) {
super.setupModule(context);
context.addBeanDeserializerModifier(new BeanDeserializerModifier() {
@Override
public JsonDeserializer<?> modifyCollectionDeserializer(final DeserializationConfig config,
final CollectionType type,
final BeanDescription beanDesc,
final JsonDeserializer<?> deserializer) {
if (deserializer instanceof CollectionDeserializer) {
return new ListDeserializer((CollectionDeserializer) deserializer);
} else {
return super.modifyCollectionDeserializer(config, type, beanDesc,
deserializer);
}
}
});
}
示例3: modifyMapDeserializer
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@Override
public JsonDeserializer<?> modifyMapDeserializer(
DeserializationConfig config, MapType type,
BeanDescription beanDesc,
JsonDeserializer<?> deserializer) {
// statements
if (isMapOfStringAndListOfStatements(type)) {
return new ModifiedMapDeserializer<String, List<JacksonStatement>>(deserializer);
}
// labels and descriptions
else if (isMapOfStringAndMonolingualTextValue(type)) {
return new ModifiedMapDeserializer<String, JacksonMonolingualTextValue>(deserializer);
}
// sitelinks
else if (isMapOfStringAndSitelink(type)) {
return new ModifiedMapDeserializer<String, JacksonSiteLink>(deserializer);
}
// aliases and miscallaneous that does not need this workaround
else {
return deserializer;
}
}
示例4: updateBuilder
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@Override
public BeanSerializerBuilder updateBuilder(SerializationConfig config, BeanDescription beanDesc,
BeanSerializerBuilder builder) {
for (BeanPropertyWriter writer : builder.getProperties()) {
JavaType propertyType = writer.getMember().getType();
Class<?> type = propertyType.getRawClass();
List<BeanPropertyDefinition> properties = getProperties(propertyType, config);
Optional.ofNullable(AnnotationUtils.findAnnotation(type, ValueObject.class))//
.filter(it -> properties.size() == 1)//
.flatMap(it -> properties.stream().findFirst())//
.ifPresent(it -> writer.assignSerializer(new PropertyAccessingSerializer(it)));
}
return builder;
}
示例5: objectMapper
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.setDeserializerModifier( new BeanDeserializerModifier() {
@Override
public JsonDeserializer<Enum> modifyEnumDeserializer( DeserializationConfig config, final JavaType type, BeanDescription beanDesc,
final JsonDeserializer<?> deserializer ) {
return new JsonDeserializer<Enum>() {
@Override
public Enum deserialize( JsonParser jp, DeserializationContext ctxt ) throws IOException {
Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
return Enum.valueOf( rawClass, jp.getValueAsString().toUpperCase() );
}
};
}
} );
module.addDeserializer( Expression.class, new ExpressionDeserializer( expressionParser() ) );
module.addDeserializer( Range.class, new RangeDeserializer() );
mapper.registerModule( module );
return mapper;
}
示例6: setupModule
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@Override
public void setupModule(final SetupContext context) {
super.setupModule(context);
context.addBeanSerializerModifier(new BeanSerializerModifier() {
public JsonSerializer<?> modifySerializer(
final SerializationConfig config,
final BeanDescription beanDesc,
final JsonSerializer<?> serializer) {
Class<?> valueClass = beanDesc.getType().getRawClass();
if (serializer instanceof BeanSerializerBase
&& MODIFIABLE_CLASSES.contains(valueClass)) {
return new FlatteningModifySerializer(
(BeanSerializerBase) serializer);
}
return serializer;
}
});
}
示例7: JacksonClientModule
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
public JacksonClientModule() {
setSerializerModifier(new BeanSerializerModifier() {
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc,
List<BeanPropertyWriter> beanProperties) {
for (BeanPropertyWriter writer : beanProperties) {
if (writer.getAnnotation(LinkedResource.class) != null) {
writer.assignSerializer(new LinkedResourceUriSerializer());
}
}
return beanProperties;
}
});
setMixInAnnotation(Resource.class, ResourceMixin.class);
}
示例8: DefaultMethodSkippingModuleProvider
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
public DefaultMethodSkippingModuleProvider() {
module = new SimpleModule();
module.setSerializerModifier(new BeanSerializerModifier() {
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
return super.changeProperties(config, beanDesc, beanProperties.stream().filter(bpw -> {
final AnnotatedMember jacksonMember = bpw.getMember();
final Member member = jacksonMember.getMember();
if (member instanceof Method) {
final Method method = (Method) member;
if (method.isDefault()) {
// only exclude default methods if they are defined on interfaces from the core components
return !method.getDeclaringClass().getName().startsWith(PACKAGE_CORE_COMPONENTS);
}
}
return true;
}).collect(Collectors.toList()));
}
});
}
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:22,代码来源:DefaultMethodSkippingModuleProvider.java
示例9: modifySerializer
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@Override
public JsonSerializer<?> modifySerializer( SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer ) {
Class<?> klass = beanDesc.getBeanClass();
if( klass == Boolean.class ) {
return new BooleanSerializer( serializer );
} else if( klass == Integer.class ) {
return new IntegerSerializer( serializer );
} else if( klass == Long.class ) {
return new LongSerializer( serializer );
} else if( klass == Float.class ) {
return new FloatSerializer( serializer );
} else if( klass == Double.class ) {
return new DoubleSerializer( serializer );
} else if( klass == BigDecimal.class ) {
return new BigDecimalSerializer( serializer );
} else if( ClassUtil.isExtendedBy( klass, Date.class ) ) {
return new DateSerializer( serializer );
}
return serializer;
}
示例10: findSerializer
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@Override
public JsonSerializer<?> findSerializer(
SerializationConfig config, JavaType type,
BeanDescription beanDesc)
{
Class<?> raw = type.getRawClass();
/* Note: PersistentCollection does not implement Collection, so we
* may get some types here...
*/
if (PersistentCollection.class.isAssignableFrom(raw)) {
// TODO: handle iterator types? Or PersistentArrayHolder?
}
if (HibernateProxy.class.isAssignableFrom(raw)) {
return new HibernateProxySerializer(isEnabled(Feature.FORCE_LAZY_LOADING));
}
return null;
}
示例11: getSerialisedFields
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override
public Set<String> getSerialisedFields(final String className) {
final Class<?> clazz;
try {
clazz = Class.forName(className);
} catch (final Exception e) {
throw new IllegalArgumentException("Class name was not recognised: " + className, e);
}
final ObjectMapper mapper = new ObjectMapper();
final JavaType type = mapper.getTypeFactory().constructType(clazz);
final BeanDescription introspection = mapper.getSerializationConfig().introspect(type);
final List<BeanPropertyDefinition> properties = introspection.findProperties();
final Set<String> fields = new HashSet<>();
for (final BeanPropertyDefinition property : properties) {
fields.add(property.getName());
}
return fields;
}
示例12: getSerialisedFields
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override
public Response getSerialisedFields(final String className) {
final Class<?> clazz;
try {
clazz = Class.forName(className);
} catch (final Exception e) {
throw new IllegalArgumentException("Class name was not recognised: " + className, e);
}
final ObjectMapper mapper = new ObjectMapper();
final JavaType type = mapper.getTypeFactory().constructType(clazz);
final BeanDescription introspection = mapper.getSerializationConfig()
.introspect(type);
final List<BeanPropertyDefinition> properties = introspection.findProperties();
final Set<String> fields = new HashSet<>();
for (final BeanPropertyDefinition property : properties) {
fields.add(property.getName());
}
return Response.ok(fields)
.header(GAFFER_MEDIA_TYPE_HEADER, GAFFER_MEDIA_TYPE)
.build();
}
示例13: jsonObjectMapper
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@Bean
public ObjectMapper jsonObjectMapper() {
final ObjectMapper jsonMapper = new ObjectMapper();
jsonMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
jsonMapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
jsonMapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
jsonMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
final SimpleModule module = new SimpleModule("FieldsMapping", Version.unknownVersion());
module.setSerializerModifier(new BeanSerializerModifier() {
@Override
public JsonSerializer<?> modifyMapSerializer(final SerializationConfig config, final MapType valueType,
final BeanDescription beanDesc, final JsonSerializer<?> serializer) {
if (FieldsMap.class.isAssignableFrom(valueType.getRawClass())) {
return new FieldsMapMixInLikeSerializer();
} else {
return super.modifyMapSerializer(config, valueType, beanDesc, serializer);
}
}
});
jsonMapper.registerModule(module);
return jsonMapper;
}
示例14: setupModule
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@Override
public void setupModule(SetupContext context) {
super.setupModule(context);
context.addBeanSerializerModifier(new BeanSerializerModifier() {
public JsonSerializer<?> modifySerializer(
SerializationConfig config,
BeanDescription beanDesc,
JsonSerializer<?> serializer) {
if (serializer instanceof BeanSerializerBase) {
return new DictionaryObjectSerializer(
(BeanSerializerBase) serializer);
}
return serializer;
}
});
}
示例15: findCollectionLikeSerializer
import com.fasterxml.jackson.databind.BeanDescription; //导入依赖的package包/类
@Override
public JsonSerializer<?> findCollectionLikeSerializer(SerializationConfig config,
CollectionLikeType type, BeanDescription beanDesc,
TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) {
Class<?> raw = type.getRawClass();
if (raw == CharSeq.class) {
return new CharSeqSerializer(type);
}
if (Seq.class.isAssignableFrom(raw)) {
return new ArraySerializer<>(type);
}
if (Set.class.isAssignableFrom(raw)) {
return new ArraySerializer<>(type);
}
if (PriorityQueue.class.isAssignableFrom(raw)) {
return new ArraySerializer<>(type);
}
return super.findCollectionLikeSerializer(config, type, beanDesc, elementTypeSerializer, elementValueSerializer);
}