本文整理匯總了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);
}