From d967e8bca7221798970542a057ca914629c09a84 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sat, 12 Oct 2024 23:30:09 -0700 Subject: [PATCH] Remove uses of TypeFactory.defaultInstance() --- .../dataformat/avro/schema/StringVisitor.java | 4 ++-- .../schema/DateTimeVisitor_builtAvroSchemaTest.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/StringVisitor.java b/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/StringVisitor.java index 48116d1d4..b8f3f5147 100644 --- a/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/StringVisitor.java +++ b/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/StringVisitor.java @@ -10,7 +10,6 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor; import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonValueFormat; -import com.fasterxml.jackson.databind.type.TypeFactory; public class StringVisitor extends JsonStringFormatVisitor.Base implements SchemaBuilder @@ -37,7 +36,8 @@ public void enumTypes(Set enums) { public Schema builtAvroSchema() { // Unlike Jackson, Avro treats characters as an int with the java.lang.Character class type. if (_type.hasRawClass(char.class) || _type.hasRawClass(Character.class)) { - return AvroSchemaHelper.numericAvroSchema(NumberType.INT, TypeFactory.defaultInstance().constructType(Character.class)); + // should we construct JavaType for `Character.class` in case of primitive or... ? + return AvroSchemaHelper.numericAvroSchema(NumberType.INT, _type); } // [dataformats-binary#179]: need special help with UUIDs, to coerce into Binary // (could actually be diff --git a/avro/src/test/java/com/fasterxml/jackson/dataformat/avro/schema/DateTimeVisitor_builtAvroSchemaTest.java b/avro/src/test/java/com/fasterxml/jackson/dataformat/avro/schema/DateTimeVisitor_builtAvroSchemaTest.java index e724115b4..90261f1cb 100644 --- a/avro/src/test/java/com/fasterxml/jackson/dataformat/avro/schema/DateTimeVisitor_builtAvroSchemaTest.java +++ b/avro/src/test/java/com/fasterxml/jackson/dataformat/avro/schema/DateTimeVisitor_builtAvroSchemaTest.java @@ -25,10 +25,8 @@ @RunWith(Parameterized.class) public class DateTimeVisitor_builtAvroSchemaTest { - private static final TypeFactory TYPE_FACTORY = TypeFactory.defaultInstance(); - @Parameter(0) - public Class testClass; + public Class testClass; @Parameter(1) public JsonParser.NumberType givenNumberType; @@ -40,7 +38,7 @@ public class DateTimeVisitor_builtAvroSchemaTest { public String expectedLogicalType; @Parameters(name = "With {0} and number type {1}") - public static Collection testData() { + public static Collection testData() { return Arrays.asList(new Object[][]{ // Java type | given number type, | expected Avro type | expected logicalType { @@ -72,14 +70,16 @@ public static Collection testData() { LocalTime.class, JsonParser.NumberType.INT, Schema.Type.INT, - "time-millis"}, + "time-millis" + } }); } @Test public void builtAvroSchemaTest() { // GIVEN - DateTimeVisitor dateTimeVisitor = new DateTimeVisitor(TYPE_FACTORY.constructSimpleType(testClass, null)); + final TypeFactory tf = TypeFactory.createDefaultInstance(); + DateTimeVisitor dateTimeVisitor = new DateTimeVisitor(tf.constructSimpleType(testClass, null)); dateTimeVisitor.numberType(givenNumberType); // WHEN