From 340492e564542c1217b85b69465d742a24d461f2 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Wed, 29 Jan 2025 16:35:31 +0100 Subject: [PATCH] Remove usage of Jackson TypeReference. Motivation: Jackson's TypeReference is only supported by the DatabindCodec. A few methods declaring TypeReference are still available on JacksonCodec and JsonEvent, such methods should be removed because the lead to incomplete usage of JacksonCodec and will simply not work at all with potential other implementations of the JSON spi. Changes: Remove methods declaring TypeReference and update tests accordingly. --- .../vertx/core/json/jackson/JacksonCodec.java | 50 -------- .../io/vertx/core/parsetools/JsonEvent.java | 13 +-- .../core/parsetools/impl/JsonEventImpl.java | 9 -- .../vertx/tests/json/JacksonDatabindTest.java | 7 +- .../io/vertx/tests/json/JsonCodecTest.java | 107 +++++++++--------- .../tests/parsetools/JsonParserTest.java | 22 ---- 6 files changed, 60 insertions(+), 148 deletions(-) diff --git a/vertx-core/src/main/java/io/vertx/core/json/jackson/JacksonCodec.java b/vertx-core/src/main/java/io/vertx/core/json/jackson/JacksonCodec.java index 4bb6b3650d5..76b3ca7fa9f 100644 --- a/vertx-core/src/main/java/io/vertx/core/json/jackson/JacksonCodec.java +++ b/vertx-core/src/main/java/io/vertx/core/json/jackson/JacksonCodec.java @@ -13,7 +13,6 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.io.SegmentedStringWriter; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.util.BufferRecycler; import com.fasterxml.jackson.core.util.ByteArrayBuilder; import io.netty.buffer.ByteBufInputStream; @@ -30,8 +29,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.Writer; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; import java.time.Instant; @@ -67,28 +64,16 @@ public T fromString(String json, Class clazz) throws DecodeException { return fromParser(createParser(json), clazz); } - public T fromString(String str, TypeReference typeRef) throws DecodeException { - return fromString(str, classTypeOf(typeRef)); - } - @Override public T fromBuffer(Buffer json, Class clazz) throws DecodeException { return fromParser(createParser(json), clazz); } - public T fromBuffer(Buffer buf, TypeReference typeRef) throws DecodeException { - return fromBuffer(buf, classTypeOf(typeRef)); - } - @Override public T fromValue(Object json, Class toValueType) { throw new DecodeException("Mapping " + toValueType.getName() + " is not available without Jackson Databind on the classpath"); } - public T fromValue(Object json, TypeReference type) { - throw new DecodeException("Mapping " + type.getType().getTypeName() + " is not available without Jackson Databind on the classpath"); - } - @Override public String toString(Object object, boolean pretty) throws EncodeException { BufferRecycler br = factory._getBufferRecycler(); @@ -378,17 +363,6 @@ private static void encodeNumber(JsonGenerator generator, Object json) throws IO } } - private static Class classTypeOf(TypeReference typeRef) { - Type type = typeRef.getType(); - if (type instanceof Class) { - return (Class) type; - } else if (type instanceof ParameterizedType) { - return (Class) ((ParameterizedType)type).getRawType(); - } else { - throw new DecodeException(); - } - } - private static T cast(Object o, Class clazz) { if (o instanceof Map) { if (!clazz.isAssignableFrom(Map.class)) { @@ -449,28 +423,4 @@ private static T cast(Object o, Class clazz) { return clazz.cast(o); } } - - /** - * Decode a given JSON string to a POJO of the given type. - * @param str the JSON string. - * @param type the type to map to. - * @param the generic type. - * @return an instance of T - * @throws DecodeException when there is a parsing or invalid mapping. - */ - public static T decodeValue(String str, TypeReference type) throws DecodeException { - return JacksonFactory.CODEC.fromString(str, type); - } - - /** - * Decode a given JSON buffer to a POJO of the given class type. - * @param buf the JSON buffer. - * @param type the type to map to. - * @param the generic type. - * @return an instance of T - * @throws DecodeException when there is a parsing or invalid mapping. - */ - public static T decodeValue(Buffer buf, TypeReference type) throws DecodeException { - return JacksonFactory.CODEC.fromBuffer(buf, type); - } } diff --git a/vertx-core/src/main/java/io/vertx/core/parsetools/JsonEvent.java b/vertx-core/src/main/java/io/vertx/core/parsetools/JsonEvent.java index fcd10f64aea..35d3fb81080 100644 --- a/vertx-core/src/main/java/io/vertx/core/parsetools/JsonEvent.java +++ b/vertx-core/src/main/java/io/vertx/core/parsetools/JsonEvent.java @@ -11,10 +11,8 @@ package io.vertx.core.parsetools; -import com.fasterxml.jackson.core.type.TypeReference; import io.vertx.codegen.annotations.DataObject; import io.vertx.codegen.annotations.GenIgnore; -import io.vertx.codegen.annotations.VertxGen; import io.vertx.core.buffer.Buffer; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; @@ -22,7 +20,7 @@ import java.time.Instant; /** - * A JSON event emited by the {@link JsonParser}. + * A JSON event emitted by the {@link JsonParser}. * * @author Julien Viet */ @@ -156,13 +154,4 @@ public interface JsonEvent { */ T mapTo(Class type); - /** - * Decodes and returns the current value as the specified {@code type}. - * - * @param type the type to decode the value to - * @return the decoded value - */ - @GenIgnore(GenIgnore.PERMITTED_TYPE) - T mapTo(TypeReference type); - } diff --git a/vertx-core/src/main/java/io/vertx/core/parsetools/impl/JsonEventImpl.java b/vertx-core/src/main/java/io/vertx/core/parsetools/impl/JsonEventImpl.java index 019b3913a31..4135aa91e33 100644 --- a/vertx-core/src/main/java/io/vertx/core/parsetools/impl/JsonEventImpl.java +++ b/vertx-core/src/main/java/io/vertx/core/parsetools/impl/JsonEventImpl.java @@ -101,15 +101,6 @@ public T mapTo(Class type) { } } - @Override - public T mapTo(TypeReference type) { - try { - return JacksonFactory.CODEC.fromValue(value, type); - } catch (Exception e) { - throw new DecodeException(e.getMessage(), e); - } - } - @Override public Integer integerValue() { if (value != null) { diff --git a/vertx-core/src/test/java/io/vertx/tests/json/JacksonDatabindTest.java b/vertx-core/src/test/java/io/vertx/tests/json/JacksonDatabindTest.java index 4a5dd926290..d9422d96c99 100644 --- a/vertx-core/src/test/java/io/vertx/tests/json/JacksonDatabindTest.java +++ b/vertx-core/src/test/java/io/vertx/tests/json/JacksonDatabindTest.java @@ -23,7 +23,6 @@ import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.core.json.jackson.DatabindCodec; -import io.vertx.core.json.jackson.JacksonCodec; import io.vertx.test.core.TestUtils; import io.vertx.test.core.VertxTestBase; import org.junit.Test; @@ -57,13 +56,15 @@ public void testGenericDecoding() { String json = Json.encode(Collections.singletonList(original)); List correct; - correct = JacksonCodec.decodeValue(json, new TypeReference>() { + DatabindCodec databindCodec = new DatabindCodec(); + + correct = databindCodec.fromString(json, new TypeReference>() { }); assertTrue(((List) correct).get(0) instanceof Pojo); assertEquals(original.value, correct.get(0).value); // same must apply if instead of string we use a buffer - correct = JacksonCodec.decodeValue(Buffer.buffer(json, "UTF8"), new TypeReference>() { + correct = databindCodec.fromBuffer(Buffer.buffer(json, "UTF8"), new TypeReference>() { }); assertTrue(((List) correct).get(0) instanceof Pojo); assertEquals(original.value, correct.get(0).value); diff --git a/vertx-core/src/test/java/io/vertx/tests/json/JsonCodecTest.java b/vertx-core/src/test/java/io/vertx/tests/json/JsonCodecTest.java index ce7daeac4d9..1c0d7292316 100644 --- a/vertx-core/src/test/java/io/vertx/tests/json/JsonCodecTest.java +++ b/vertx-core/src/test/java/io/vertx/tests/json/JsonCodecTest.java @@ -22,6 +22,7 @@ import io.vertx.core.json.jackson.DatabindCodec; import io.vertx.core.json.jackson.JacksonCodec; import io.vertx.test.core.TestUtils; +import org.junit.Assume; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -69,10 +70,10 @@ public static Collection mappers() { }); } - private final JacksonCodec mapper; + private final JacksonCodec codec; - public JsonCodecTest(JacksonCodec mapper) { - this.mapper = mapper; + public JsonCodecTest(JacksonCodec codec) { + this.codec = codec; } @Test @@ -96,7 +97,7 @@ public void testEncodeJsonObject() { String strBytes = TestUtils.toBase64String(bytes); String expected = "{\"mystr\":\"foo\",\"myint\":123,\"mylong\":1234,\"myfloat\":1.23,\"mydouble\":2.34,\"" + "myboolean\":true,\"mybyte\":255,\"mybinary\":\"" + strBytes + "\",\"mybuffer\":\"" + strBytes + "\",\"myinstant\":\"" + ISO_INSTANT.format(now) + "\",\"mynull\":null,\"myobj\":{\"foo\":\"bar\"},\"myarr\":[\"foo\",123]}"; - String json = mapper.toString(jsonObject); + String json = codec.toString(jsonObject); assertEquals(expected, json); } @@ -118,7 +119,7 @@ public void testEncodeJsonArray() { jsonArray.add(new JsonArray().add("foo").add(123)); String strBytes = TestUtils.toBase64String(bytes); String expected = "[\"foo\",123,1234,1.23,2.34,true,124,\"" + strBytes + "\",\"" + strBytes + "\",null,{\"foo\":\"bar\"},[\"foo\",123]]"; - String json = mapper.toString(jsonArray); + String json = codec.toString(jsonArray); assertEquals(expected, json); } @@ -144,7 +145,7 @@ public void testEncodeJsonObjectToBuffer() { Buffer expected = Buffer.buffer("{\"mystr\":\"foo\",\"myint\":123,\"mylong\":1234,\"myfloat\":1.23,\"mydouble\":2.34,\"" + "myboolean\":true,\"mybinary\":\"" + strBytes + "\",\"mybuffer\":\"" + strBytes + "\",\"myinstant\":\"" + ISO_INSTANT.format(now) + "\",\"mynull\":null,\"myobj\":{\"foo\":\"bar\"},\"myarr\":[\"foo\",123]}", "UTF-8"); - Buffer json = mapper.toBuffer(jsonObject); + Buffer json = codec.toBuffer(jsonObject); assertArrayEquals(expected.getBytes(), json.getBytes()); } @@ -165,7 +166,7 @@ public void testEncodeJsonArrayToBuffer() { jsonArray.add(new JsonArray().add("foo").add(123)); String strBytes = TestUtils.toBase64String(bytes); Buffer expected = Buffer.buffer("[\"foo\",123,1234,1.23,2.34,true,\"" + strBytes + "\",\"" + strBytes + "\",null,{\"foo\":\"bar\"},[\"foo\",123]]", "UTF-8"); - Buffer json = mapper.toBuffer(jsonArray); + Buffer json = codec.toBuffer(jsonArray); assertArrayEquals(expected.getBytes(), json.getBytes()); } @@ -203,7 +204,7 @@ public void testEncodeJsonObjectPrettily() { " }," + Utils.LINE_SEPARATOR + " \"myarr\" : [ \"foo\", 123 ]" + Utils.LINE_SEPARATOR + "}"; - String json = mapper.toString(jsonObject, true); + String json = codec.toString(jsonObject, true); assertEquals(expected, json); } @@ -226,7 +227,7 @@ public void testEncodeJsonArrayPrettily() { String expected = "[ \"foo\", 123, 1234, 1.23, 2.34, true, \"" + strBytes + "\", \"" + strBytes + "\", null, {" + Utils.LINE_SEPARATOR + " \"foo\" : \"bar\"" + Utils.LINE_SEPARATOR + "}, [ \"foo\", 123 ] ]"; - String json = mapper.toString(jsonArray, true); + String json = codec.toString(jsonArray, true); assertEquals(expected, json); } @@ -238,8 +239,8 @@ public void testDecodeJsonObject() { String strInstant = ISO_INSTANT.format(now); String json = "{\"mystr\":\"foo\",\"myint\":123,\"mylong\":1234,\"myfloat\":1.23,\"mydouble\":2.34,\"" + "myboolean\":true,\"mybyte\":124,\"mybinary\":\"" + strBytes + "\",\"mybuffer\":\"" + strBytes + "\",\"myinstant\":\"" + strInstant + "\",\"mynull\":null,\"myobj\":{\"foo\":\"bar\"},\"myarr\":[\"foo\",123]}"; - JsonObject obj = new JsonObject(mapper.fromString(json, Map.class)); - assertEquals(json, mapper.toString(obj)); + JsonObject obj = new JsonObject(codec.fromString(json, Map.class)); + assertEquals(json, codec.toString(obj)); assertEquals("foo", obj.getString("mystr")); assertEquals(Integer.valueOf(123), obj.getInteger("myint")); assertEquals(Long.valueOf(1234), obj.getLong("mylong")); @@ -268,7 +269,7 @@ public void testDecodeJsonArray() { Instant now = Instant.now(); String strInstant = ISO_INSTANT.format(now); String json = "[\"foo\",123,1234,1.23,2.34,true,124,\"" + strBytes + "\",\"" + strBytes + "\",\"" + strInstant + "\",null,{\"foo\":\"bar\"},[\"foo\",123]]"; - JsonArray arr = new JsonArray(mapper.fromString(json, List.class)); + JsonArray arr = new JsonArray(codec.fromString(json, List.class)); assertEquals("foo", arr.getString(0)); assertEquals(Integer.valueOf(123), arr.getInteger(1)); assertEquals(Long.valueOf(1234l), arr.getLong(2)); @@ -307,8 +308,8 @@ public void testDecodeJsonObjectWithComments() { " line comment this time inside the JSON object itself\n" + "*/\n" + "}"; - JsonObject json = new JsonObject(mapper.fromString(jsonWithComments, Map.class)); - assertEquals("{\"foo\":\"bar\"}", mapper.toString(json)); + JsonObject json = new JsonObject(codec.fromString(jsonWithComments, Map.class)); + assertEquals("{\"foo\":\"bar\"}", codec.toString(json)); } // Strict JSON doesn't allow comments but we do so users can add comments to config files etc @@ -328,20 +329,20 @@ public void testDecodeJsonArrayWithComments() { " line comment this time inside the JSON array itself\n" + "*/\n" + "]"; - JsonArray json = new JsonArray(mapper.fromString(jsonWithComments, List.class)); - assertEquals("[\"foo\",\"bar\"]", mapper.toString(json)); + JsonArray json = new JsonArray(codec.fromString(jsonWithComments, List.class)); + assertEquals("[\"foo\",\"bar\"]", codec.toString(json)); } @Test public void testDecodeJsonObjectWithInvalidJson() { for (String test : new String[] { "3", "\"3", "qiwjdoiqwjdiqwjd", "{\"foo\":1},{\"bar\":2}", "{\"foo\":1} 1234" }) { try { - mapper.fromString(test, Map.class); + codec.fromString(test, Map.class); fail(); } catch (DecodeException ignore) { } try { - mapper.fromBuffer(Buffer.buffer(test), Map.class); + codec.fromBuffer(Buffer.buffer(test), Map.class); fail(); } catch (DecodeException ignore) { } @@ -352,12 +353,12 @@ public void testDecodeJsonObjectWithInvalidJson() { public void testDecodeJsonArrayWithInvalidJson() { for (String test : new String[] { "3", "\"3", "qiwjdoiqwjdiqwjd", "[1],[2]", "[] 1234" }) { try { - mapper.fromString(test, List.class); + codec.fromString(test, List.class); fail(); } catch (DecodeException ignore) { } try { - mapper.fromBuffer(Buffer.buffer(test), List.class); + codec.fromBuffer(Buffer.buffer(test), List.class); fail(); } catch (DecodeException ignore) { } @@ -367,7 +368,7 @@ public void testDecodeJsonArrayWithInvalidJson() { @Test public void encodeCustomTypeInstant() { Instant now = Instant.now(); - String json = mapper.toString(now); + String json = codec.toString(now); assertNotNull(json); // the RFC is one way only Instant decoded = Instant.from(ISO_INSTANT.parse(json.substring(1, json.length() - 1))); @@ -378,17 +379,17 @@ public void encodeCustomTypeInstant() { public void decodeCustomTypeInstant() { Instant now = Instant.now(); String json = '"' + ISO_INSTANT.format(now) + '"'; - Instant decoded = mapper.fromString(json, Instant.class); + Instant decoded = codec.fromString(json, Instant.class); assertEquals(now, decoded); } @Test public void encodeCustomTypeBinary() { byte[] data = new byte[] { 'h', 'e', 'l', 'l', 'o'}; - String json = mapper.toString(data); + String json = codec.toString(data); assertNotNull(json); assertEquals("\"aGVsbG8\"", json); - json = mapper.toString(Buffer.buffer(data)); + json = codec.toString(Buffer.buffer(data)); assertNotNull(json); assertEquals("\"aGVsbG8\"", json); } @@ -396,22 +397,22 @@ public void encodeCustomTypeBinary() { @Test public void decodeCustomTypeBinary() { // base64 encoded hello - byte[] data = mapper.fromString("\"aGVsbG8\"", byte[].class); + byte[] data = codec.fromString("\"aGVsbG8\"", byte[].class); assertEquals("hello", new String(data)); - Buffer buff = mapper.fromString("\"aGVsbG8\"", Buffer.class); + Buffer buff = codec.fromString("\"aGVsbG8\"", Buffer.class); assertEquals("hello", buff.toString()); } @Test public void encodeNull() { - String json = mapper.toString(null); + String json = codec.toString(null); assertNotNull(json); assertEquals("null", json); } @Test public void encodeToBuffer() { - Buffer json = mapper.toBuffer("Hello World!"); + Buffer json = codec.toBuffer("Hello World!"); assertNotNull(json); // json strings are always UTF8 assertEquals("\"Hello World!\"", json.toString()); @@ -419,13 +420,14 @@ public void encodeToBuffer() { @Test public void encodeNullToBuffer() { - Buffer json = mapper.toBuffer(null); + Buffer json = codec.toBuffer(null); assertNotNull(json); assertEquals("null", json.toString()); } @Test public void testDecodeValue() { + Assume.assumeTrue(codec instanceof DatabindCodec); assertDecodeValue(Buffer.buffer("42"), 42, INTEGER_TYPE_REF); assertDecodeValue(Buffer.buffer("42"), 42L, LONG_TYPE_REF); assertDecodeValue(Buffer.buffer("\"foobar\""), "foobar", STRING_TYPE_REF); @@ -440,34 +442,35 @@ public void testDecodeValue() { @Test public void testEnumValue() { // just a random enum - Buffer json = mapper.toBuffer(WebSocketVersion.V13); + Buffer json = codec.toBuffer(WebSocketVersion.V13); assertNotNull(json); assertEquals("\"V13\"", json.toString()); - mapper.fromBuffer(json, WebSocketVersion.class); + codec.fromBuffer(json, WebSocketVersion.class); } @Test public void testBigNumberValues() { - Buffer json = mapper.toBuffer(new BigDecimal("124567890124567890.09876543210987654321")); + Buffer json = codec.toBuffer(new BigDecimal("124567890124567890.09876543210987654321")); assertNotNull(json); assertEquals("124567890124567890.09876543210987654321", json.toString()); - Buffer json2 = mapper.toBuffer(new BigInteger("12456789009876543211245678900987654321")); + Buffer json2 = codec.toBuffer(new BigInteger("12456789009876543211245678900987654321")); assertNotNull(json2); assertEquals("12456789009876543211245678900987654321", json2.toString()); } private void assertDecodeValue(Buffer buffer, T expected, TypeReference ref) { + DatabindCodec databindCodec = (DatabindCodec) codec; Type type = ref.getType(); Class clazz = type instanceof Class ? (Class) type : (Class) ((ParameterizedType) type).getRawType(); - assertEquals(expected, mapper.fromBuffer(buffer, clazz)); - assertEquals(expected, mapper.fromBuffer(buffer, ref)); - assertEquals(expected, mapper.fromString(buffer.toString(StandardCharsets.UTF_8), clazz)); - assertEquals(expected, mapper.fromString(buffer.toString(StandardCharsets.UTF_8), ref)); + assertEquals(expected, codec.fromBuffer(buffer, clazz)); + assertEquals(expected, databindCodec.fromBuffer(buffer, ref)); + assertEquals(expected, codec.fromString(buffer.toString(StandardCharsets.UTF_8), clazz)); + assertEquals(expected, databindCodec.fromString(buffer.toString(StandardCharsets.UTF_8), ref)); Buffer nullValue = Buffer.buffer("null"); - assertNull(mapper.fromBuffer(nullValue, clazz)); - assertNull(mapper.fromBuffer(nullValue, ref)); - assertNull(mapper.fromString(nullValue.toString(StandardCharsets.UTF_8), clazz)); - assertNull(mapper.fromString(nullValue.toString(StandardCharsets.UTF_8), ref)); + assertNull(codec.fromBuffer(nullValue, clazz)); + assertNull(databindCodec.fromBuffer(nullValue, ref)); + assertNull(codec.fromString(nullValue.toString(StandardCharsets.UTF_8), clazz)); + assertNull(databindCodec.fromString(nullValue.toString(StandardCharsets.UTF_8), ref)); } @Test @@ -482,29 +485,29 @@ public void testDecodeStringUnknowContent() { private void testDecodeUnknowContent(boolean asBuffer) { String number = String.valueOf(1); - assertEquals(1, asBuffer ? mapper.fromBuffer(Buffer.buffer(number)) : mapper.fromString(number)); + assertEquals(1, asBuffer ? codec.fromBuffer(Buffer.buffer(number)) : codec.fromString(number)); String bool = Boolean.TRUE.toString(); - assertEquals(true, asBuffer ?mapper.fromBuffer(Buffer.buffer(bool)) : mapper.fromString(bool)); + assertEquals(true, asBuffer ? codec.fromBuffer(Buffer.buffer(bool)) : codec.fromString(bool)); String text = "\"whatever\""; - assertEquals("whatever", asBuffer ? mapper.fromBuffer(Buffer.buffer(text)) : mapper.fromString(text)); + assertEquals("whatever", asBuffer ? codec.fromBuffer(Buffer.buffer(text)) : codec.fromString(text)); String nullText = "null"; - assertNull(asBuffer ? mapper.fromBuffer(Buffer.buffer(nullText)) : mapper.fromString(nullText)); + assertNull(asBuffer ? codec.fromBuffer(Buffer.buffer(nullText)) : codec.fromString(nullText)); JsonObject obj = new JsonObject().put("foo", "bar"); - assertEquals(obj, asBuffer ? mapper.fromBuffer(obj.toBuffer()) : mapper.fromString(obj.toString())); + assertEquals(obj, asBuffer ? codec.fromBuffer(obj.toBuffer()) : codec.fromString(obj.toString())); JsonArray arr = new JsonArray().add(1).add(false).add("whatever").add(obj); - assertEquals(arr, asBuffer ? mapper.fromBuffer(arr.toBuffer()) : mapper.fromString(arr.toString())); + assertEquals(arr, asBuffer ? codec.fromBuffer(arr.toBuffer()) : codec.fromString(arr.toString())); String invalidText = "\"invalid"; try { if (asBuffer) { - mapper.fromBuffer(Buffer.buffer(invalidText)); + codec.fromBuffer(Buffer.buffer(invalidText)); } else { - mapper.fromString(invalidText); + codec.fromString(invalidText); } fail(); } catch (DecodeException ignore) { @@ -533,7 +536,7 @@ public void testEncodeCollectionState() { assertEquals("{\"key\":[\"foo\"]}", checkMap(new JsonArray().add("foo"))); assertEquals("[[\"foo\"]]", checkList(new JsonArray().add("foo"))); Locale locale = Locale.FRANCE; - if (mapper instanceof DatabindCodec) { + if (codec instanceof DatabindCodec) { assertEquals("{\"key\":\"fr_FR\"}", checkMap(locale)); assertEquals("[\"fr_FR\"]", checkList(locale)); } else { @@ -565,11 +568,11 @@ public void testEncodeCollectionState() { private String checkMap(Object o) { Map map = new HashMap<>(); map.put("key", o); - return mapper.toString(map, false); + return codec.toString(map, false); } private String checkList(Object o) { - return mapper.toString(Collections.singletonList(o), false); + return codec.toString(Collections.singletonList(o), false); } } diff --git a/vertx-core/src/test/java/io/vertx/tests/parsetools/JsonParserTest.java b/vertx-core/src/test/java/io/vertx/tests/parsetools/JsonParserTest.java index a97bd920fca..ada86d08353 100644 --- a/vertx-core/src/test/java/io/vertx/tests/parsetools/JsonParserTest.java +++ b/vertx-core/src/test/java/io/vertx/tests/parsetools/JsonParserTest.java @@ -11,7 +11,6 @@ package io.vertx.tests.parsetools; -import com.fasterxml.jackson.core.type.TypeReference; import io.vertx.core.Handler; import io.vertx.core.buffer.Buffer; import io.vertx.core.json.DecodeException; @@ -602,16 +601,6 @@ public void testObjectMappingError() { assertEquals(1, errors.size()); } - @Test - public void testObjectMappingWithTypeReference() { - JsonParser parser = JsonParser.newParser(); - List values = new ArrayList<>(); - parser.objectValueMode(); - parser.handler(event -> values.add(event.mapTo(new TypeReference() {}))); - parser.handle(new JsonObject().put("f", "the-value").toBuffer()); - assertEquals(Collections.singletonList(new TheObject("the-value")), values); - } - @Test public void testArrayMapping() { JsonParser parser = JsonParser.newParser(); @@ -643,17 +632,6 @@ public void testArrayMappingError() { assertEquals(1, errors.size()); } - @Test - public void testArrayMappingWithTypeReference() { - JsonParser parser = JsonParser.newParser(); - List values = new ArrayList<>(); - parser.arrayValueMode(); - parser.handler(event -> values.add(event.mapTo(new TypeReference>() {}))); - parser.handle(new JsonArray().add(0).add(1).add(2).toBuffer()); - assertEquals(Collections.singletonList(Arrays.asList(0L, 1L, 2L)), values); - assertEquals(LinkedList.class, values.get(0).getClass()); - } - public static class TheObject { private String f;