本文整理汇总了Java中com.fasterxml.jackson.databind.ser.Serializers类的典型用法代码示例。如果您正苦于以下问题:Java Serializers类的具体用法?Java Serializers怎么用?Java Serializers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Serializers类属于com.fasterxml.jackson.databind.ser包,在下文中一共展示了Serializers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SerializerFactoryConfig
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
protected SerializerFactoryConfig(Serializers[] paramArrayOfSerializers1, Serializers[] paramArrayOfSerializers2, BeanSerializerModifier[] paramArrayOfBeanSerializerModifier)
{
Serializers[] arrayOfSerializers1;
if (paramArrayOfSerializers1 == null)
arrayOfSerializers1 = NO_SERIALIZERS;
else
arrayOfSerializers1 = paramArrayOfSerializers1;
this._additionalSerializers = arrayOfSerializers1;
Serializers[] arrayOfSerializers2;
if (paramArrayOfSerializers2 == null)
arrayOfSerializers2 = NO_SERIALIZERS;
else
arrayOfSerializers2 = paramArrayOfSerializers2;
this._additionalKeySerializers = arrayOfSerializers2;
BeanSerializerModifier[] arrayOfBeanSerializerModifier;
if (paramArrayOfBeanSerializerModifier == null)
arrayOfBeanSerializerModifier = NO_MODIFIERS;
else
arrayOfBeanSerializerModifier = paramArrayOfBeanSerializerModifier;
this._modifiers = arrayOfBeanSerializerModifier;
}
示例2: modules
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
@Test
public void modules() {
NumberSerializer serializer1 = new NumberSerializer(Integer.class);
SimpleModule module = new SimpleModule();
module.addSerializer(Integer.class, serializer1);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules(module).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertSame(serializer1, serializers.findSerializer(null, SimpleType.construct(Integer.class), null));
}
示例3: modulesToInstallByClass
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void modulesToInstallByClass() {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modulesToInstall(CustomIntegerModule.class).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertSame(CustomIntegerSerializer.class, serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass());
}
示例4: serializerByType
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
@Test
public void serializerByType() {
JsonSerializer<Number> serializer = new NumberSerializer(Integer.class);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
.modules(new ArrayList<>()) // Disable well-known modules detection
.serializerByType(Boolean.class, serializer).build();
assertTrue(getSerializerFactoryConfig(objectMapper).hasSerializers());
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertSame(serializer, serializers.findSerializer(null, SimpleType.construct(Boolean.class), null));
}
示例5: setModules
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
@Test
public void setModules() {
NumberSerializer serializer = new NumberSerializer(Integer.class);
SimpleModule module = new SimpleModule();
module.addSerializer(Integer.class, serializer);
this.factory.setModules(Arrays.asList(new Module[]{module}));
this.factory.afterPropertiesSet();
ObjectMapper objectMapper = this.factory.getObject();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertSame(serializer, serializers.findSerializer(null, SimpleType.construct(Integer.class), null));
}
示例6: withAdditionalKeySerializers
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
public final SerializerFactoryConfig withAdditionalKeySerializers(Serializers paramSerializers)
{
if (paramSerializers == null)
throw new IllegalArgumentException("Can not pass null Serializers");
Serializers[] arrayOfSerializers = (Serializers[])ArrayBuilders.insertInListNoDup(this._additionalKeySerializers, paramSerializers);
return new SerializerFactoryConfig(this._additionalSerializers, arrayOfSerializers, this._modifiers);
}
示例7: findSerializer
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
public JsonSerializer<?> findSerializer(SerializationConfig paramSerializationConfig, JavaType paramJavaType, BeanDescription paramBeanDescription)
{
Class localClass = paramJavaType.getRawClass();
if ((localClass.getName().startsWith("javax.xml.")) || (!hasSupertypeStartingWith(localClass, "javax.xml.")))
{
if (doesImplement(localClass, "org.w3c.dom.Node"))
return (JsonSerializer)instantiate("com.fasterxml.jackson.databind.ext.DOMSerializer");
return null;
}
Object localObject = instantiate("com.fasterxml.jackson.databind.ext.CoreXMLSerializers");
if (localObject == null)
return null;
return ((Serializers)localObject).findSerializer(paramSerializationConfig, paramJavaType, paramBeanDescription);
}
示例8: modulesToInstallByInstance
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
@Test
public void modulesToInstallByInstance() {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modulesToInstall(new CustomIntegerModule()).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertSame(CustomIntegerSerializer.class, serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass());
}
示例9: completeSetup
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
@Test
public void completeSetup() {
NopAnnotationIntrospector annotationIntrospector = NopAnnotationIntrospector.instance;
ObjectMapper objectMapper = new ObjectMapper();
this.factory.setObjectMapper(objectMapper);
assertTrue(this.factory.isSingleton());
assertEquals(ObjectMapper.class, this.factory.getObjectType());
Map<Class<?>, JsonDeserializer<?>> deserializers = new HashMap<Class<?>, JsonDeserializer<?>>();
deserializers.put(Date.class, new DateDeserializer());
JsonSerializer<Class<?>> serializer1 = new ClassSerializer();
JsonSerializer<Number> serializer2 = new NumberSerializer(Integer.class);
// Disable well-known modules detection
this.factory.setModules(new ArrayList<>());
this.factory.setSerializers(serializer1);
this.factory.setSerializersByType(Collections.singletonMap(Boolean.class, serializer2));
this.factory.setDeserializersByType(deserializers);
this.factory.setAnnotationIntrospector(annotationIntrospector);
this.factory.setFeaturesToEnable(SerializationFeature.FAIL_ON_EMPTY_BEANS,
DeserializationFeature.UNWRAP_ROOT_VALUE,
JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER,
JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS);
this.factory.setFeaturesToDisable(MapperFeature.AUTO_DETECT_GETTERS,
MapperFeature.AUTO_DETECT_FIELDS,
JsonParser.Feature.AUTO_CLOSE_SOURCE,
JsonGenerator.Feature.QUOTE_FIELD_NAMES);
assertFalse(getSerializerFactoryConfig(objectMapper).hasSerializers());
assertFalse(getDeserializerFactoryConfig(objectMapper).hasDeserializers());
this.factory.setSerializationInclusion(Include.NON_NULL);
this.factory.afterPropertiesSet();
assertSame(objectMapper, this.factory.getObject());
assertTrue(getSerializerFactoryConfig(objectMapper).hasSerializers());
assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers());
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertSame(serializer1, serializers.findSerializer(null, SimpleType.construct(Class.class), null));
assertSame(serializer2, serializers.findSerializer(null, SimpleType.construct(Boolean.class), null));
assertNull(serializers.findSerializer(null, SimpleType.construct(Number.class), null));
assertSame(annotationIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector());
assertSame(annotationIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector());
assertTrue(objectMapper.getSerializationConfig().isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS));
assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE));
assertTrue(objectMapper.getFactory().isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
assertTrue(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS));
assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
assertFalse(objectMapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
assertFalse(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
assertSame(Include.NON_NULL, objectMapper.getSerializationConfig().getSerializationInclusion());
}
示例10: keySerializers
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
public final Iterable<Serializers> keySerializers()
{
return ArrayBuilders.arrayAsIterable(this._additionalKeySerializers);
}
示例11: serializers
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
public final Iterable<Serializers> serializers()
{
return ArrayBuilders.arrayAsIterable(this._additionalSerializers);
}
示例12: withAdditionalSerializers
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
public final SerializerFactoryConfig withAdditionalSerializers(Serializers paramSerializers)
{
if (paramSerializers == null)
throw new IllegalArgumentException("Can not pass null Serializers");
return new SerializerFactoryConfig((Serializers[])ArrayBuilders.insertInListNoDup(this._additionalSerializers, paramSerializers), this._additionalKeySerializers, this._modifiers);
}
示例13: customSerializers
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
@Override
protected Iterable<Serializers> customSerializers() {
return null;
}
示例14: addSerializers
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
/**
* Method that module can use to register additional serializers to use for
* handling types.
*
* @param s Object that can be called to find serializer for types supported
* by module (null returned for non-supported types)
*/
public void addSerializers(Serializers s);
示例15: addKeySerializers
import com.fasterxml.jackson.databind.ser.Serializers; //导入依赖的package包/类
/**
* Method that module can use to register additional serializers to use for
* handling Map key values (which are separate from value serializers because
* they must write <code>JsonToken.FIELD_NAME</code> instead of String value).
*/
public void addKeySerializers(Serializers s);