Example usage for com.fasterxml.jackson.databind ObjectMapper getFactory

List of usage examples for com.fasterxml.jackson.databind ObjectMapper getFactory

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper getFactory.

Prototype

@Override
public JsonFactory getFactory() 

Source Link

Document

Method that can be used to get hold of JsonFactory that this mapper uses if it needs to construct JsonParser s and/or JsonGenerator s.

Usage

From source file:ren.hankai.cordwood.jackson.DateSerializerTest.java

@Test
public void testSerializeWithCustomFormat() throws Exception {
    final ObjectMapper om = new ObjectMapper();
    final StringWriter sw = new StringWriter();
    final JsonGenerator jgen = om.getFactory().createGenerator(sw);

    final Date date = DateUtils.parseDate("2018-11-12", "yyyy-MM-dd");
    final DateSerializer ser = new DateSerializer("yyyy|MM|dd");
    ser.serialize(date, jgen, om.getSerializerProvider());
    jgen.flush();/*from w  w w.j  av a2  s  .  c o m*/

    Assert.assertEquals("\"2018|11|12\"", sw.toString());
}

From source file:ren.hankai.cordwood.jackson.DateTimeSerializerTest.java

@Test
public void testSerialize() throws Exception {
    final ObjectMapper om = new ObjectMapper();
    final StringWriter sw = new StringWriter();
    final JsonGenerator jgen = om.getFactory().createGenerator(sw);

    final Date date = DateUtils.parseDate("2018-11-12 13:22:22", "yyyy-MM-dd HH:mm:ss");
    final DateTimeSerializer ser = new DateTimeSerializer();
    ser.serialize(date, jgen, om.getSerializerProvider());
    jgen.flush();/*from   w ww .j a va  2s.c  o m*/

    Assert.assertEquals("\"2018-11-12 13:22:22\"", sw.toString());
}

From source file:ren.hankai.cordwood.jackson.DateTimeSerializerTest.java

@Test
public void testSerializeWithCustomFormat() throws Exception {
    final ObjectMapper om = new ObjectMapper();
    final StringWriter sw = new StringWriter();
    final JsonGenerator jgen = om.getFactory().createGenerator(sw);

    final Date date = DateUtils.parseDate("2018-11-12 11:11:11", "yyyy-MM-dd HH:mm:ss");
    final DateTimeSerializer ser = new DateTimeSerializer("yyyy|MM|dd HH|mm|ss");
    ser.serialize(date, jgen, om.getSerializerProvider());
    jgen.flush();/*from w  w  w .  j  a  va  2 s . com*/

    Assert.assertEquals("\"2018|11|12 11|11|11\"", sw.toString());
}

From source file:no.ssb.jsonstat.v2.deser.DatasetDeserializerTest.java

@Test
public void testParseValues() throws Exception {
    ObjectMapper mapper = new ObjectMapper();

    JsonParser mapParser = mapper.getFactory()
            .createParser("" + "{ " + "  \"0\": 10," + "  \"1\": 20," + "  \"3\": 30," + "  \"4\": 40}");
    mapParser.nextValue();/*w  w w  .  ja v a2s . com*/

    JsonParser arrayParser = mapper.getFactory().createParser("[ 10, 20, null, 30, 40 ]");
    arrayParser.nextValue();

    List<Number> fromMap = ds.parseValues(mapParser, null);
    List<Number> fromArray = ds.parseValues(arrayParser, null);
    List<Number> expected = Lists.newArrayList(10, 20, null, 30, 40);

    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(fromMap).as("deserialize values from map").isEqualTo(expected);
    softly.assertThat(fromArray).as("deserialize values from array").isEqualTo(expected);
    softly.assertAll();

}

From source file:org.dswarm.xsd2jsonschema.model.JSRoot.java

public void render(final ObjectMapper mapper, final Writer writer) throws IOException {
    render(mapper.getFactory(), writer);

}

From source file:org.dswarm.xsd2jsonschema.model.JSRoot.java

public void render(final ObjectMapper mapper, final OutputStream out) throws IOException {
    render(mapper.getFactory(), out);

}

From source file:org.n52.tamis.core.test.json.deserialize.CapabilitiesDeserializer_Test.java

/**
 * Parses the example document located at
 * "src/test/resources/extendedCapabilities_example.json" and deserializes
 * its content into an instance of {@link Capabilities_Tamis}
 *///from  ww  w. j a  v a  2 s. c  o  m
@Test
public void test() {
    try {

        input = this.getClass().getResourceAsStream(EXTENDED_CAPABILITIES_EXAMPLE_JSON);

        ObjectMapper objectMapper = new ObjectMapper();
        JsonFactory jsonFactory = objectMapper.getFactory();

        this.jsonParser = jsonFactory.createParser(input);

        Capabilities_Tamis capabilities_short = capabilitiesDeserializer.deserialize(jsonParser, null);

        /*
         * Assert that values of the intantiated Capabilities_Tamis object
         * match the expected parameters from the example document
         */
        Assert.assertNotNull(capabilities_short);
        Assert.assertEquals("52North WPS 4.0.0-SNAPSHOT", capabilities_short.getLabel());
        Assert.assertEquals("contact@52north.org", capabilities_short.getContact());
        Assert.assertEquals(String.valueOf(SERVICE_ID_CONSTANT), capabilities_short.getId().toString());
        Assert.assertEquals("WPS", capabilities_short.getType());

    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:ren.hankai.cordwood.jackson.DateDeserializerTest.java

@Test
public void testDeserializeInvalidDate() throws Exception {
    final ObjectMapper om = new ObjectMapper();
    final DateDeserializer des = new DateDeserializer();
    final JsonParser jp = om.getFactory().createParser("{\"date\": \"20180901\"}");

    String val = null;
    do {//w  w w .  j  a  va  2 s  .  co  m
        val = jp.nextTextValue();
    } while (val == null);

    final Date date = des.deserialize(jp, om.getDeserializationContext());
    Assert.assertNull(date);
}

From source file:ren.hankai.cordwood.jackson.DateDeserializerTest.java

@Test
public void testDeserialize() throws Exception {
    final ObjectMapper om = new ObjectMapper();
    final DateDeserializer des = new DateDeserializer();
    final JsonParser jp = om.getFactory().createParser("{\"date\": \"2018-09-01\"}");

    String val = null;
    do {/*from  w  w  w  .j  ava  2s.  c om*/
        val = jp.nextTextValue();
    } while (val == null);

    final Date date = des.deserialize(jp, om.getDeserializationContext());
    final Date expDate = DateUtils.parseDate(jp.getText(), "yyyy-MM-dd");
    Assert.assertTrue(DateUtils.isSameDay(date, expDate));
}

From source file:org.eluder.logback.ext.jackson.JsonWriter.java

public JsonWriter(OutputStream os, Charset charset, ObjectMapper mapper) throws IOException {
    generator = mapper.getFactory().createGenerator(new OutputStreamWriter(os, charset))
            .configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false)
            .setPrettyPrinter(new MinimalPrettyPrinter(""));
}