本文整理汇总了Java中com.fasterxml.jackson.databind.SerializationConfig类的典型用法代码示例。如果您正苦于以下问题:Java SerializationConfig类的具体用法?Java SerializationConfig怎么用?Java SerializationConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializationConfig类属于com.fasterxml.jackson.databind包,在下文中一共展示了SerializationConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupModule
import com.fasterxml.jackson.databind.SerializationConfig; //导入依赖的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: getObjectMapper
import com.fasterxml.jackson.databind.SerializationConfig; //导入依赖的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;
}
示例3: build
import com.fasterxml.jackson.databind.SerializationConfig; //导入依赖的package包/类
public static AnnotatedClass build(final Class<?> declaringClass, final SerializationConfig serializationConfig) {
for (final Method method : AnnotatedClass.class.getMethods()) {
if (CONSTRUCT_METHOD_NAME.equals(method.getName()) &&
method.getParameterTypes().length == 3) {
return ExceptionUtil.wrapCatchedExceptions(new Callable<AnnotatedClass>() {
@Override
public AnnotatedClass call() throws Exception {
return buildAnnotatedClass(method, declaringClass, serializationConfig);
}
}, "Exception while building AnnotatedClass");
}
}
throw new IllegalStateException(CANNOT_FIND_PROPER_METHOD);
}
示例4: getName
import com.fasterxml.jackson.databind.SerializationConfig; //导入依赖的package包/类
protected Optional<String> getName(Method method) {
ObjectMapper objectMapper = context.getObjectMapper();
SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
String name = ClassUtils.getGetterFieldName(method);
Annotation[] declaredAnnotations = method.getDeclaredAnnotations();
AnnotationMap annotationMap = buildAnnotationMap(declaredAnnotations);
int paramsLength = method.getParameterAnnotations().length;
AnnotationMap[] paramAnnotations = new AnnotationMap[paramsLength];
for (int i = 0; i < paramsLength; i++) {
AnnotationMap parameterAnnotationMap = buildAnnotationMap(method.getParameterAnnotations()[i]);
paramAnnotations[i] = parameterAnnotationMap;
}
AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(method.getDeclaringClass(), serializationConfig);
AnnotatedMethod annotatedField = AnnotatedMethodBuilder.build(annotatedClass, method, annotationMap, paramAnnotations);
return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForGetterMethod(serializationConfig, annotatedField, name));
}
return Optional.empty();
}
示例5: updateBuilder
import com.fasterxml.jackson.databind.SerializationConfig; //导入依赖的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;
}
示例6: setupModule
import com.fasterxml.jackson.databind.SerializationConfig; //导入依赖的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.SerializationConfig; //导入依赖的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.SerializationConfig; //导入依赖的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.SerializationConfig; //导入依赖的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.SerializationConfig; //导入依赖的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: _figureFallbackType
import com.fasterxml.jackson.databind.SerializationConfig; //导入依赖的package包/类
protected JavaType _figureFallbackType(SerializationConfig config,
JavaType persistentType)
{
// Alas, PersistentTypes are NOT generics-aware... meaning can't specify parameterization
Class<?> raw = persistentType.getRawClass();
TypeFactory tf = config.getTypeFactory();
if (Map.class.isAssignableFrom(raw)) {
return tf.constructMapType(Map.class, Object.class, Object.class);
}
if (List.class.isAssignableFrom(raw)) {
return tf.constructCollectionType(List.class, Object.class);
}
if (Set.class.isAssignableFrom(raw)) {
return tf.constructCollectionType(Set.class, Object.class);
}
// ok, just Collection of some kind
return tf.constructCollectionType(Collection.class, Object.class);
}
示例12: jsonObjectMapper
import com.fasterxml.jackson.databind.SerializationConfig; //导入依赖的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;
}
示例13: setupModule
import com.fasterxml.jackson.databind.SerializationConfig; //导入依赖的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;
}
});
}
示例14: findCollectionLikeSerializer
import com.fasterxml.jackson.databind.SerializationConfig; //导入依赖的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);
}
示例15: buildTypeSerializer
import com.fasterxml.jackson.databind.SerializationConfig; //导入依赖的package包/类
public TypeSerializer buildTypeSerializer(SerializationConfig paramSerializationConfig, JavaType paramJavaType, Collection<NamedType> paramCollection)
{
if (this._idType == JsonTypeInfo.Id.NONE)
return null;
TypeIdResolver localTypeIdResolver = idResolver(paramSerializationConfig, paramJavaType, paramCollection, true, false);
switch (1.$SwitchMap$com$fasterxml$jackson$annotation$JsonTypeInfo$As[this._includeAs.ordinal()])
{
default:
break;
case 1:
return new AsArrayTypeSerializer(localTypeIdResolver, null);
case 2:
return new AsPropertyTypeSerializer(localTypeIdResolver, null, this._typeProperty);
case 3:
return new AsWrapperTypeSerializer(localTypeIdResolver, null);
case 4:
return new AsExternalTypeSerializer(localTypeIdResolver, null, this._typeProperty);
}
throw new IllegalStateException("Do not know how to construct standard type serializer for inclusion type: " + this._includeAs);
}