com.fasterxml.jackson.databind.json.JsonMapper Java Examples

The following examples show how to use com.fasterxml.jackson.databind.json.JsonMapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestSimpleMaterializedInterfaces.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
/**
 * Test to verify that materializer will by default create exception-throwing methods
 * for "unknown" abstract methods
 */
public void testPartialBean() throws Exception
{
    AbstractTypeMaterializer mat = new AbstractTypeMaterializer();
    // ensure that we will only get deferred error methods
    mat.disable(AbstractTypeMaterializer.Feature.FAIL_ON_UNMATERIALIZED_METHOD);
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(new MrBeanModule(mat))
            .build();
    PartialBean bean = mapper.readValue("{\"ok\":true}", PartialBean.class);
    assertNotNull(bean);
    assertTrue(bean.isOk());
    // and then exception
    try {
        bean.foobar();
    } catch (UnsupportedOperationException e) {
        verifyException(e, "Unimplemented method 'foobar'");
    }
}
 
Example #2
Source File: TestRange.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
public void testDefaultBoundTypeOnlyLowerBoundTypeInformedWithClosedConfigured() throws Exception
{
    String json = "{\"lowerEndpoint\": 2, \"lowerBoundType\": \"OPEN\", \"upperEndpoint\": 3}";

    GuavaModule mod = new GuavaModule().defaultBoundType(BoundType.CLOSED);
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(mod)
            .build();
    @SuppressWarnings("unchecked")
    Range<Integer> r = (Range<Integer>) mapper.readValue(json, Range.class);

    assertEquals(Integer.valueOf(2), r.lowerEndpoint());
    assertEquals(Integer.valueOf(3), r.upperEndpoint());
    assertEquals(BoundType.OPEN, r.lowerBoundType());
    assertEquals(BoundType.CLOSED, r.upperBoundType());
}
 
Example #3
Source File: TestRange.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
public void testSnakeCaseNamingStrategy() throws Exception
{
    String json = "{\"lower_endpoint\": 12, \"lower_bound_type\": \"CLOSED\", \"upper_endpoint\": 33, \"upper_bound_type\": \"CLOSED\"}";

    GuavaModule mod = new GuavaModule().defaultBoundType(BoundType.CLOSED);
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(mod)
            .propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
            .build();

    @SuppressWarnings("unchecked")
    Range<Integer> r = (Range<Integer>) mapper.readValue(json, Range.class);

    assertEquals(Integer.valueOf(12), r.lowerEndpoint());
    assertEquals(Integer.valueOf(33), r.upperEndpoint());

    assertEquals(BoundType.CLOSED, r.lowerBoundType());
    assertEquals(BoundType.CLOSED, r.upperBoundType());
}
 
Example #4
Source File: TestRange.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
public void testDefaultBoundTypeNoBoundTypeInformedWithClosedConfigured() throws Exception
{
    String json = "{\"lowerEndpoint\": 2, \"upperEndpoint\": 3}";

    GuavaModule mod = new GuavaModule().defaultBoundType(BoundType.CLOSED);
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(mod)
            .build();

    @SuppressWarnings("unchecked")
    Range<Integer> r = (Range<Integer>) mapper.readValue(json, Range.class);

    assertEquals(Integer.valueOf(2), r.lowerEndpoint());
    assertEquals(Integer.valueOf(3), r.upperEndpoint());
    assertEquals(BoundType.CLOSED, r.lowerBoundType());
    assertEquals(BoundType.CLOSED, r.upperBoundType());
}
 
Example #5
Source File: StratumProtocol.java    From besu with Apache License 2.0 6 votes vote down vote up
default void handleHashrateSubmit(
    final JsonMapper mapper,
    final MiningCoordinator miningCoordinator,
    final StratumConnection conn,
    final JsonRpcRequest message)
    throws IOException {
  final String hashRate = message.getRequiredParameter(0, String.class);
  final String id = message.getRequiredParameter(1, String.class);
  String response =
      mapper.writeValueAsString(
          new JsonRpcSuccessResponse(
              message.getId(),
              miningCoordinator.submitHashRate(
                  id, Bytes.fromHexString(hashRate).toBigInteger().longValue())));
  conn.send(response + "\n");
}
 
Example #6
Source File: TestRange.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
public void testDefaultBoundTypeOnlyUpperBoundTypeInformedWithClosedConfigured() throws Exception
{
    String json = "{\"lowerEndpoint\": 1, \"upperEndpoint\": 3, \"upperBoundType\": \"OPEN\"}";

    GuavaModule mod = new GuavaModule().defaultBoundType(BoundType.CLOSED);
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(mod)
            .build();
    @SuppressWarnings("unchecked")
    Range<Integer> r = (Range<Integer>) mapper.readValue(json, Range.class);

    assertEquals(Integer.valueOf(1), r.lowerEndpoint());
    assertEquals(Integer.valueOf(3), r.upperEndpoint());
    assertEquals(BoundType.CLOSED, r.lowerBoundType());
    assertEquals(BoundType.OPEN, r.upperBoundType());
}
 
Example #7
Source File: Range56Test.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
public void testSnakeCaseNamingStrategy() throws Exception
{
    String json = "{\"lower_endpoint\": 12, \"lower_bound_type\": \"CLOSED\", \"upper_endpoint\": 33, \"upper_bound_type\": \"CLOSED\"}";

    GuavaModule mod = new GuavaModule().defaultBoundType(BoundType.CLOSED);
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(mod)
            .propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
            .build();

    @SuppressWarnings("unchecked")
    Range<Integer> r = (Range<Integer>) mapper.readValue(json, Range.class);

    assertEquals(Integer.valueOf(12), r.lowerEndpoint());
    assertEquals(Integer.valueOf(33), r.upperEndpoint());

    assertEquals(BoundType.CLOSED, r.lowerBoundType());
    assertEquals(BoundType.CLOSED, r.upperBoundType());
}
 
Example #8
Source File: SpspClientDefaults.java    From quilt with Apache License 2.0 6 votes vote down vote up
private static ObjectMapper defaultMapper() {
  final ObjectMapper objectMapper = JsonMapper.builder()
      .serializationInclusion(JsonInclude.Include.NON_EMPTY)
      .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
      .configure(JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS, false)
      .build()
      .registerModule(new Jdk8Module())
      .registerModule(new InterledgerModule(Encoding.BASE64));
  objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
  objectMapper.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true);
  return objectMapper;
}
 
Example #9
Source File: TestRange.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
public void testDefaultBoundTypeBothBoundTypesOpenWithClosedConfigured() throws Exception
{
    String json = "{\"lowerEndpoint\": 1, \"lowerBoundType\": \"OPEN\", \"upperEndpoint\": 3, \"upperBoundType\": \"OPEN\"}";

    GuavaModule mod = new GuavaModule().defaultBoundType(BoundType.CLOSED);
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(mod)
            .build();
    @SuppressWarnings("unchecked")
    Range<Integer> r = (Range<Integer>) mapper.readValue(json, Range.class);

    assertEquals(Integer.valueOf(1), r.lowerEndpoint());
    assertEquals(Integer.valueOf(3), r.upperEndpoint());

    assertEquals(BoundType.OPEN, r.lowerBoundType());
    assertEquals(BoundType.OPEN, r.upperBoundType());
}
 
Example #10
Source File: TestRange.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
public void testDefaultBoundTypeBothBoundTypesClosedWithOpenConfigured() throws Exception
{
    String json = "{\"lowerEndpoint\": 12, \"lowerBoundType\": \"CLOSED\", \"upperEndpoint\": 33, \"upperBoundType\": \"CLOSED\"}";

    GuavaModule mod = new GuavaModule().defaultBoundType(BoundType.CLOSED);
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(mod)
            .build();
    @SuppressWarnings("unchecked")
    Range<Integer> r = (Range<Integer>) mapper.readValue(json, Range.class);

    assertEquals(Integer.valueOf(12), r.lowerEndpoint());
    assertEquals(Integer.valueOf(33), r.upperEndpoint());

    assertEquals(BoundType.CLOSED, r.lowerBoundType());
    assertEquals(BoundType.CLOSED, r.upperBoundType());
}
 
Example #11
Source File: ManualDatabindPerf.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception
{
    if (args.length != 0) {
        System.err.println("Usage: java ...");
        System.exit(1);
    }
    ObjectMapper vanilla = new ObjectMapper();
    ObjectMapper burnt = JsonMapper.builder()
            .addModule(new AfterburnerModule())
            .build();

    /*
    TestPojo input = new TestPojo(1245, -99, "Billy-Bob",
            new Value(27, 116));

    new ManualDatabindPerf().test(vanilla, burnt, input, TestPojo.class);
    */

    MediaItem media = MediaItem.buildItem();
    new ManualDatabindPerf().test(vanilla, burnt, media, MediaItem.class);
}
 
Example #12
Source File: ConstraintViolationProblemModuleTest.java    From problem-spring-web with MIT License 6 votes vote down vote up
@Test
void shouldSerializeWithoutAutoDetect() throws JsonProcessingException {
    final JsonMapper mapper = JsonMapper.builder()
            .disable(MapperFeature.AUTO_DETECT_FIELDS)
            .disable(MapperFeature.AUTO_DETECT_GETTERS)
            .disable(MapperFeature.AUTO_DETECT_IS_GETTERS)
            .addModule(new ProblemModule())
            .addModule(new ConstraintViolationProblemModule())
            .build();

    final Violation violation = new Violation("bob", "was missing");
    final ConstraintViolationProblem unit = new ConstraintViolationProblem(BAD_REQUEST, singletonList(violation));

    with(mapper.writeValueAsString(unit))
            .assertThat("status", is(400))
            .assertThat("type", is(ConstraintViolationProblem.TYPE_VALUE))
            .assertThat("title", is("Constraint Violation"))
            .assertThat("violations", hasSize(1))
            .assertThat("violations.*.field", contains("bob"))
            .assertThat("violations.*.message", contains("was missing"));
}
 
Example #13
Source File: TestCreatorsDelegating.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public void testWithFactoryAndDelegate() throws Exception
{
    ObjectMapper mapper = JsonMapper.builder()
            .injectableValues(new InjectableValues.Std()
                    .addValue(String.class, "Fygar"))
            .addModule(new AfterburnerModule())
            .build();
    FactoryBean711 bean = null;
    try {
        bean = mapper.readValue("38", FactoryBean711.class);
    } catch (JsonMappingException e) {
        fail("Did not expect problems, got: "+e.getMessage());
    }
    assertEquals(38, bean.age);
    assertEquals("Fygar", bean.name1);
    assertEquals("Fygar", bean.name2);
}
 
Example #14
Source File: TestSimpleTypes.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public void testPlainGetAndSet() throws Exception
{
    // First, simple attempt fails
    try {
        MAPPER.readValue("{}", JustGetAndSet.class);
        fail("Should not pass");
    } catch (JsonMappingException e) {
        verifyException(e, "Unrecognized abstract method");
    }

    // but can make work with config:
    AbstractTypeMaterializer mat = new AbstractTypeMaterializer();
    mat.disable(AbstractTypeMaterializer.Feature.FAIL_ON_UNMATERIALIZED_METHOD);
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(new MrBeanModule(mat))
            .build();
    JustGetAndSet value = mapper.readValue("{}", JustGetAndSet.class);
    assertNotNull(value);
}
 
Example #15
Source File: ObjectMapperModule.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectMapper get()
{
    ObjectMapper mapper = objectMapper;
    if (mapper == null) {
        final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector();
        AnnotationIntrospector defaultAI = new JacksonAnnotationIntrospector();
        MapperBuilder<?,?> builder = JsonMapper.builder()
                .injectableValues(new GuiceInjectableValues(injector))
                .annotationIntrospector(new AnnotationIntrospectorPair(guiceIntrospector, defaultAI))
                .addModules(modulesToAdd);
        for (Provider<? extends Module> provider : providedModules) {
            builder = builder.addModule(provider.get());
        }
        mapper = builder.build();

      /*
  } else {
        // 05-Feb-2017, tatu: _Should_ be fine, considering instances are now (3.0) truly immutable.
      //    But if this turns out to be problematic, may need to consider addition of `copy()`
      //    back in databind
      mapper = mapper.copy();
      */
  }
  return mapper;
}
 
Example #16
Source File: InjectOsgiServiceTest.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception
{
    bundleContext = mock(BundleContext.class);
    doThrow(new InvalidSyntaxException("", "")).when(bundleContext).createFilter(anyString());
    Filter filter = mock(Filter.class);
    when(filter.toString()).thenReturn(OSGI_FILTER);
    doReturn(filter).when(bundleContext).createFilter(OSGI_FILTER);
    when(bundleContext.getServiceReferences(eq(Service.class.getName()), anyString())).thenReturn(new ServiceReference[]{mock(ServiceReference.class)});
    when(bundleContext.getService(any(ServiceReference.class))).thenReturn(mock(Service.class));
    
    mapper = JsonMapper.builder()
            .addModule(new OsgiJacksonModule(bundleContext))
            .build();
}
 
Example #17
Source File: TestXmlID2.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public void testIdWithJacksonRules() throws Exception
{
    String expected = "[{\"id\":11,\"username\":\"11\",\"email\":\"[email protected]\","
            +"\"department\":{\"id\":9,\"name\":\"department9\",\"employees\":["
            +"11,{\"id\":22,\"username\":\"22\",\"email\":\"[email protected]\","
            +"\"department\":9}]}},22,{\"id\":33,\"username\":\"33\",\"email\":\"[email protected]\",\"department\":null}]";
    ObjectMapper mapper = JsonMapper.builder()
    // true -> ignore XmlIDREF annotation
            .annotationIntrospector(new JaxbAnnotationIntrospector(true))
            .build();
    
    // first, with default settings (first NOT as id)
    List<User> users = getUserList();
    String json = mapper.writeValueAsString(users);
    assertEquals(expected, json);

    List<User> result = mapper.readValue(json, new TypeReference<List<User>>() { });
    assertEquals(3, result.size());
    assertEquals(Long.valueOf(11), result.get(0).id);
    assertEquals(Long.valueOf(22), result.get(1).id);
    assertEquals(Long.valueOf(33), result.get(2).id);
}
 
Example #18
Source File: TestXmlID2.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public void testIdWithJaxbRules() throws Exception
{
    ObjectMapper mapper = JsonMapper.builder()
    // but then also variant where ID is ALWAYS used for XmlID / XmlIDREF
            .annotationIntrospector(new JaxbAnnotationIntrospector())
            .build();
    List<User> users = getUserList();
    final String json = mapper.writeValueAsString(users);
    String expected = "[{\"id\":11,\"username\":\"11\",\"email\":\"[email protected]\",\"department\":9}"
            +",{\"id\":22,\"username\":\"22\",\"email\":\"[email protected]\",\"department\":9}"
            +",{\"id\":33,\"username\":\"33\",\"email\":\"[email protected]\",\"department\":null}]";
    
    assertEquals(expected, json);

    // However, there is no way to resolve those back, without some external mechanism...
}
 
Example #19
Source File: TestCreatorsDelegating.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public void testWithCtorAndDelegate() throws Exception
{
    ObjectMapper mapper = JsonMapper.builder()
            .injectableValues(new InjectableValues.Std()
                    .addValue(String.class, "Pooka"))
            .addModule(new AfterburnerModule())
            .build();
    CtorBean711 bean = null;
    try {
        bean = mapper.readValue("38", CtorBean711.class);
    } catch (JsonMappingException e) {
        fail("Did not expect problems, got: "+e.getMessage());
    }
    assertEquals(38, bean.age);
    assertEquals("Pooka", bean.name);
}
 
Example #20
Source File: TestCollectionDeser.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public void testUnwrapSingleArray() throws Exception
{
    final ObjectMapper mapper = JsonMapper.builder()
            .enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
            .addModule(new AfterburnerModule())
            .build();
    final Integer intValue = mapper.readValue("[ 1 ]", Integer.class);
    assertEquals(Integer.valueOf(1), intValue);

    final String strValue = mapper.readValue("[ \"abc\" ]", String.class);
    assertEquals("abc", strValue);

    // and then via POJO. First, array of POJOs
    IntBean b1 = mapper.readValue(aposToQuotes("[{ 'value' : 123 }]"), IntBean.class);
    assertNotNull(b1);
    assertEquals(123, b1.value);

    // and then array of ints within POJO
    IntBean b2 = mapper.readValue(aposToQuotes("{ 'value' : [ 123 ] }"), IntBean.class);
    assertNotNull(b2);
    assertEquals(123, b2.value);
}
 
Example #21
Source File: TestSerializePerf.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception
    {
//        JsonFactory f = new org.codehaus.jackson.smile.SmileFactory();
        JsonFactory f = new JsonFactory();
        ObjectMapper mapperSlow = JsonMapper.builder(f)
        // !!! TEST -- to get profile info, comment out:
                .addModule(new AfterburnerModule())
                .build();

        ObjectMapper mapperFast = JsonMapper.builder(f)
                .addModule(new AfterburnerModule())
                .build();
        new TestSerializePerf().testWith(mapperSlow, mapperFast);
    }
 
Example #22
Source File: IsolatedClassLoaderTest.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void testBeanWithSeparateClassLoader() throws IOException {
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(new AfterburnerModule())
            .build();

    Object bean = makeObjectFromIsolatedClassloader();
    String result = mapper.writeValueAsString(bean);
    assertEquals("{\"value\":\"some string\"}", result);
}
 
Example #23
Source File: TestStdSerializerOverrides.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void testLongSerOverideNoAfterburner() throws Exception
{
    // First, baseline, no custom serializer
    assertEquals(aposToQuotes("{'value':999}"),
            VANILLA_MAPPER.writeValueAsString(new SimpleLongBean()));

    // and then with custom serializer, but no Afterburner
    String json = JsonMapper.builder()
            .addModule(new SimpleModule("module", Version.unknownVersion())
                .addSerializer(Long.class, new MyLongSerializer())
                .addSerializer(Long.TYPE, new MyLongSerializer()))
            .build()
            .writeValueAsString(new SimpleLongBean());
    assertEquals(aposToQuotes("{'value':-999}"), json);
}
 
Example #24
Source File: TestStdDeserializerOverrides.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void testStringDeserOverideNoAfterburner() throws Exception
{
    final String json = "{\"field\": \"value &amp; value\"}";
    final String EXP = "value & value";
    Issue59Bean resultVanilla = JsonMapper.builder()
            .addModule(new SimpleModule("module", Version.unknownVersion())
                    .addDeserializer(String.class, new DeAmpDeserializer()))
            .build()
            .readValue(json, Issue59Bean.class);
    assertEquals(EXP, resultVanilla.field);
}
 
Example #25
Source File: TestCollectionDeser.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void testIntMethod() throws Exception
{
    final ObjectMapper mapper = JsonMapper.builder()
            .configure(MapperFeature.USE_GETTERS_AS_SETTERS, true)
            .addModule(new AfterburnerModule())
            .build();
    CollectionBean bean = mapper.readValue("{\"stuff\":[\"a\",\"b\"]}",
            CollectionBean.class);
    assertEquals(2, bean.x.size());
    assertEquals(TreeSet.class, bean.x.getClass());
}
 
Example #26
Source File: TestYearMonthSerializationWithCustomFormatter.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
private YearMonth deserializeWith(String json, DateTimeFormatter f) throws Exception {
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(new SimpleModule()
                    .addDeserializer(YearMonth.class, new YearMonthDeserializer(f)))
            .build();
    return mapper.readValue("\"" + json + "\"", YearMonth.class);
}
 
Example #27
Source File: TestStdSerializerOverrides.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void testStringSerOverideNoAfterburner() throws Exception
{
    String json = JsonMapper.builder()
            .addModule(new SimpleModule("module", Version.unknownVersion())
                    .addSerializer(String.class, new MyStringSerializer()))
            .build()
            .writeValueAsString(new SimpleStringBean());
    assertEquals("{\"field\":\"Foo:value\"}", json);
}
 
Example #28
Source File: BaseJaxbTest.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
protected MapperBuilder<?,?> getJaxbAndJacksonMapperBuilder()
{
    return JsonMapper.builder()
            .annotationIntrospector(new AnnotationIntrospectorPair(
                    new JaxbAnnotationIntrospector(),
                    new JacksonAnnotationIntrospector()));
}
 
Example #29
Source File: TestDeserializePerf.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception
    {
//        JsonFactory f = new org.codehaus.jackson.smile.SmileFactory();
        JsonFactory f = new JsonFactory();
        ObjectMapper mapperSlow = new ObjectMapper(f);
        
        // !!! TEST -- to get profile info, comment out:
//        mapperSlow.registerModule(new AfterburnerModule());

        ObjectMapper mapperFast = JsonMapper.builder(f)
                .addModule(new AfterburnerModule())
                .build();
        new TestDeserializePerf().testWith(mapperSlow, mapperFast);
    }
 
Example #30
Source File: TestStdSerializerOverrides.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void testIntSerOverideNoAfterburner() throws Exception
{
    // First, baseline, no custom serializer
    assertEquals(aposToQuotes("{'value':42}"),
            VANILLA_MAPPER.writeValueAsString(new SimpleIntBean()));

    // and then with custom serializer, but no Afterburner
    String json = JsonMapper.builder()
            .addModule(new SimpleModule("module", Version.unknownVersion())
                .addSerializer(Integer.class, new MyIntSerializer())
                .addSerializer(Integer.TYPE, new MyIntSerializer()))
            .build()
            .writeValueAsString(new SimpleIntBean());
    assertEquals(aposToQuotes("{'value':-42}"), json);
}