Search in sources :

Example 6 with Serializers

use of com.fasterxml.jackson.databind.ser.Serializers in project spring-framework by spring-projects.

the class Jackson2ObjectMapperBuilderTests method modulesToInstallByInstance.

@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());
}
Also used : Serializers(com.fasterxml.jackson.databind.ser.Serializers) SimpleSerializers(com.fasterxml.jackson.databind.module.SimpleSerializers) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with Serializers

use of com.fasterxml.jackson.databind.ser.Serializers in project spring-framework by spring-projects.

the class Jackson2ObjectMapperBuilderTests method serializerByType.

@Test
public void serializerByType() {
    JsonSerializer<Number> serializer = new NumberSerializer(Integer.class);
    ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules(// Disable well-known modules detection
    new ArrayList<>()).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));
}
Also used : NumberSerializer(com.fasterxml.jackson.databind.ser.std.NumberSerializer) Serializers(com.fasterxml.jackson.databind.ser.Serializers) SimpleSerializers(com.fasterxml.jackson.databind.module.SimpleSerializers) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 SimpleSerializers (com.fasterxml.jackson.databind.module.SimpleSerializers)7 Serializers (com.fasterxml.jackson.databind.ser.Serializers)7 Test (org.junit.Test)7 NumberSerializer (com.fasterxml.jackson.databind.ser.std.NumberSerializer)5 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)2 NopAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)2 ClassSerializer (com.fasterxml.jackson.databind.ser.std.ClassSerializer)2 HashMap (java.util.HashMap)2 JsonSerializer (com.fasterxml.jackson.databind.JsonSerializer)1 Module (com.fasterxml.jackson.databind.Module)1 Deserializers (com.fasterxml.jackson.databind.deser.Deserializers)1 DateDeserializers (com.fasterxml.jackson.databind.deser.std.DateDeserializers)1 DateDeserializer (com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1