Search in sources :

Example 1 with DatabindCodec

use of io.vertx.core.json.jackson.DatabindCodec in project vert.x by eclipse.

the class JsonCodecTest method testEncodeCollectionState.

@Test
public void testEncodeCollectionState() {
    assertEquals("{\"key\":\"QQ\"}", checkMap(new byte[] { 'A' }));
    assertEquals("[\"QQ\"]", checkList(new byte[] { 'A' }));
    assertEquals("{\"key\":\"QQ\"}", checkMap(Buffer.buffer("A")));
    assertEquals("[\"QQ\"]", checkList(Buffer.buffer("A")));
    Instant instant = Instant.ofEpochMilli(0);
    assertEquals("{\"key\":\"1970-01-01T00:00:00Z\"}", checkMap(instant));
    assertEquals("[\"1970-01-01T00:00:00Z\"]", checkList(instant));
    assertEquals("{\"key\":\"MICROSECONDS\"}", checkMap(TimeUnit.MICROSECONDS));
    assertEquals("[\"MICROSECONDS\"]", checkList(TimeUnit.MICROSECONDS));
    BigInteger bigInt = new BigInteger("123456789");
    assertEquals("{\"key\":123456789}", checkMap(bigInt));
    assertEquals("[123456789]", checkList(bigInt));
    BigDecimal bigDec = new BigDecimal(bigInt).divide(new BigDecimal("100"));
    assertEquals("{\"key\":1234567.89}", checkMap(bigDec));
    assertEquals("[1234567.89]", checkList(bigDec));
    assertEquals("{\"key\":{\"foo\":\"bar\"}}", checkMap(new JsonObject().put("foo", "bar")));
    assertEquals("[{\"foo\":\"bar\"}]", checkList(new JsonObject().put("foo", "bar")));
    assertEquals("{\"key\":[\"foo\"]}", checkMap(new JsonArray().add("foo")));
    assertEquals("[[\"foo\"]]", checkList(new JsonArray().add("foo")));
    Locale locale = Locale.FRANCE;
    if (mapper instanceof DatabindCodec) {
        assertEquals("{\"key\":\"fr_FR\"}", checkMap(locale));
        assertEquals("[\"fr_FR\"]", checkList(locale));
    } else {
        CharSequence cs = HttpHeaders.ACCEPT;
        assertFalse(cs instanceof String);
        try {
            checkMap(cs);
            fail();
        } catch (EncodeException ignore) {
        }
        try {
            checkList(cs);
            fail();
        } catch (EncodeException ignore) {
        }
        try {
            checkMap(locale);
            fail();
        } catch (EncodeException ignore) {
        }
        try {
            checkList(locale);
            fail();
        } catch (EncodeException ignore) {
        }
    }
}
Also used : Locale(java.util.Locale) Instant(java.time.Instant) BigInteger(java.math.BigInteger) DatabindCodec(io.vertx.core.json.jackson.DatabindCodec) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with DatabindCodec

use of io.vertx.core.json.jackson.DatabindCodec in project vert.x by eclipse.

the class JsonEncodeBenchmark method setup.

@Setup
public void setup() {
    ClassLoader classLoader = getClass().getClassLoader();
    small = loadJson(classLoader.getResource("small_bench.json"));
    wide = loadJson(classLoader.getResource("wide_bench.json"));
    deep = loadJson(classLoader.getResource("deep_bench.json"));
    jacksonCodec = new JacksonCodec();
    databindCodec = new DatabindCodec();
}
Also used : JacksonCodec(io.vertx.core.json.jackson.JacksonCodec) DatabindCodec(io.vertx.core.json.jackson.DatabindCodec)

Example 3 with DatabindCodec

use of io.vertx.core.json.jackson.DatabindCodec in project vert.x by eclipse.

the class JsonDecodeBenchmark method setup.

@Setup
public void setup() {
    small = loadJsonAsBuffer("small_bench.json");
    wide = loadJsonAsBuffer("wide_bench.json");
    deep = loadJsonAsBuffer("deep_bench.json");
    smallString = small.toString();
    wideString = wide.toString();
    deepString = deep.toString();
    jacksonCodec = new JacksonCodec();
    databindCodec = new DatabindCodec();
}
Also used : JacksonCodec(io.vertx.core.json.jackson.JacksonCodec) DatabindCodec(io.vertx.core.json.jackson.DatabindCodec)

Aggregations

DatabindCodec (io.vertx.core.json.jackson.DatabindCodec)3 JacksonCodec (io.vertx.core.json.jackson.JacksonCodec)2 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Instant (java.time.Instant)1 Locale (java.util.Locale)1 Test (org.junit.Test)1