Skip to content

Commit 25b931b

Browse files
authored
Merge branch '2.19' into tests
2 parents ad34228 + 4080ae2 commit 25b931b

File tree

14 files changed

+137
-29
lines changed

14 files changed

+137
-29
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
run: ./mvnw -B -q -ff -ntp test
6363
- name: Publish code coverage
6464
if: ${{ matrix.release_build && github.event_name != 'pull_request' }}
65-
uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1
65+
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
6666
with:
6767
token: ${{ secrets.CODECOV_TOKEN }}
6868
file: ./target/site/jacoco/jacoco.xml

avro/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ abstractions.
9393
<groupId>org.moditect</groupId>
9494
<artifactId>moditect-maven-plugin</artifactId>
9595
</plugin>
96+
<!-- 05-Jul-2020, tatu: Add generation of Gradle Module Metadata -->
97+
<!-- 28-Feb-2025, jjohannes: Apply plugin last as it has to be the last of all 'package phase' plugins -->
98+
<plugin>
99+
<groupId>org.gradlex</groupId>
100+
<artifactId>gradle-module-metadata-maven-plugin</artifactId>
101+
</plugin>
96102
</plugins>
97103
</build>
98104
</project>

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/AvroSchemaHelper.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,21 +264,29 @@ public static Schema parseJsonSchema(String json) {
264264
/**
265265
* Constructs a new enum schema
266266
*
267+
* @param intr Introspector to use to find default enum value
267268
* @param bean Enum type to use for name / description / namespace
268269
* @param values List of enum names
270+
*
269271
* @return An {@link org.apache.avro.Schema.Type#ENUM ENUM} schema.
270272
*/
271-
public static Schema createEnumSchema(BeanDescription bean, List<String> values)
273+
public static Schema createEnumSchema(AnnotationIntrospector intr,
274+
BeanDescription bean, List<String> values)
272275
{
273276
final JavaType enumType = bean.getType();
277+
@SuppressWarnings("unchecked")
278+
Class<Enum<?>> rawEnumClass = (Class<Enum<?>>) enumType.getRawClass();
279+
final Enum<?> defaultEnumValue = intr.findDefaultEnumValue(bean.getClassInfo(),
280+
rawEnumClass.getEnumConstants());
281+
final String namespace = getNamespace(enumType, bean.getClassInfo());
274282
final Schema avroSchema;
275-
276283
try {
277284
avroSchema = Schema.createEnum(
278285
getName(enumType),
279286
bean.findClassDescription(),
280-
getNamespace(enumType, bean.getClassInfo()),
281-
values);
287+
namespace,
288+
values,
289+
defaultEnumValue != null ? defaultEnumValue.toString() : null);
282290
} catch (SchemaParseException spe) {
283291
final String msg = String.format("Problem generating Avro `Schema` for Enum type %s: %s",
284292
ClassUtil.getTypeDescription(enumType), spe.getMessage());

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/EnumVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public Schema builtAvroSchema() {
4141
}
4242

4343
BeanDescription bean = _provider.getConfig().introspectClassAnnotations(_type);
44-
Schema schema = AvroSchemaHelper.createEnumSchema(bean, new ArrayList<>(_enums));
44+
Schema schema = AvroSchemaHelper.createEnumSchema(_provider.getAnnotationIntrospector(),
45+
bean, new ArrayList<>(_enums));
4546
_schemas.addSchema(_type, schema);
4647
return schema;
4748
}

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/AvroTestBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ public Image(String uri, String title, int w, int h, Size s)
244244
public void setSize(Size s) { _size = s; }
245245
}
246246

247+
// public because needed by "AvroAliasTest"
247248
public enum Size { SMALL, LARGE; }
248249

249250
/*

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/EnumTest.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
package com.fasterxml.jackson.dataformat.avro;
22

3+
import java.util.stream.Collectors;
4+
import java.util.stream.Stream;
5+
36
import org.junit.jupiter.api.Test;
47

8+
import org.apache.avro.Schema;
9+
import org.apache.avro.Schema.Type;
10+
11+
import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
12+
import com.fasterxml.jackson.annotation.JsonProperty;
13+
import com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaGenerator;
14+
515
import static org.junit.jupiter.api.Assertions.assertEquals;
616
import static org.junit.jupiter.api.Assertions.assertNotNull;
717

@@ -35,6 +45,19 @@ protected static class EmployeeStr {
3545
public String gender;
3646
}
3747

48+
protected enum ABC {
49+
A,
50+
B,
51+
@JsonEnumDefaultValue
52+
C;
53+
}
54+
55+
protected static class ABCDefaultClass {
56+
public String name;
57+
@JsonProperty(required = true)
58+
public ABC abc;
59+
}
60+
3861
private final AvroMapper MAPPER = newMapper();
3962

4063
@Test
@@ -127,4 +150,35 @@ public void test_avroSchemaWithString_fromStringValueToEnumValue() throws Except
127150
assertEquals(Gender.F, output.gender);
128151
}
129152

153+
// [dataformats-binary#388]: Default value for enums with class
154+
@Test
155+
public void testClassEnumWithDefault() throws Exception
156+
{
157+
AvroSchemaGenerator gen = new AvroSchemaGenerator();
158+
159+
MAPPER.acceptJsonFormatVisitor(ABCDefaultClass.class, gen);
160+
AvroSchema schema = gen.getGeneratedSchema();
161+
assertNotNull(schema);
162+
163+
String json = schema.getAvroSchema().toString(true);
164+
assertNotNull(json);
165+
166+
// And read it back too just for fun
167+
AvroSchema s2 = MAPPER.schemaFrom(json);
168+
assertNotNull(s2);
169+
170+
Schema avroSchema = s2.getAvroSchema();
171+
172+
// String name, int value
173+
assertEquals(Type.RECORD, avroSchema.getType());
174+
Schema.Field f = avroSchema.getField("abc");
175+
assertNotNull(f);
176+
assertEquals("abc", f.name());
177+
178+
assertEquals(Type.ENUM, f.schema().getType());
179+
assertEquals(ABC.C.toString(), f.schema().getEnumDefault());
180+
assertEquals(Stream.of(ABC.values())
181+
.map(ABC::name)
182+
.collect(Collectors.toList()), f.schema().getEnumSymbols());
183+
}
130184
}

cbor/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,14 @@ encoded data using Jackson abstractions (streaming API, data binding, tree model
7070
will have to use `moduleInfoFile` as anything else requires JDK 9+
7171
-->
7272
<plugin>
73-
<groupId>org.moditect</groupId>
74-
<artifactId>moditect-maven-plugin</artifactId>
73+
<groupId>org.moditect</groupId>
74+
<artifactId>moditect-maven-plugin</artifactId>
75+
</plugin>
76+
<!-- 05-Jul-2020, tatu: Add generation of Gradle Module Metadata -->
77+
<!-- 28-Feb-2025, jjohannes: Apply plugin last as it has to be the last of all 'package phase' plugins -->
78+
<plugin>
79+
<groupId>org.gradlex</groupId>
80+
<artifactId>gradle-module-metadata-maven-plugin</artifactId>
7581
</plugin>
7682
</plugins>
7783
</build>

ion/pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ tree model)
3939
<dependency>
4040
<groupId>com.amazon.ion</groupId>
4141
<artifactId>ion-java</artifactId>
42-
<version>1.11.9</version>
42+
<version>1.11.10</version>
4343
</dependency>
4444

4545
<!-- Extends Jackson core, databind -->
@@ -83,8 +83,14 @@ tree model)
8383
will have to use `moduleInfoFile` as anything else requires JDK 9+
8484
-->
8585
<plugin>
86-
<groupId>org.moditect</groupId>
87-
<artifactId>moditect-maven-plugin</artifactId>
86+
<groupId>org.moditect</groupId>
87+
<artifactId>moditect-maven-plugin</artifactId>
88+
</plugin>
89+
<!-- 05-Jul-2020, tatu: Add generation of Gradle Module Metadata -->
90+
<!-- 28-Feb-2025, jjohannes: Apply plugin last as it has to be the last of all 'package phase' plugins -->
91+
<plugin>
92+
<groupId>org.gradlex</groupId>
93+
<artifactId>gradle-module-metadata-maven-plugin</artifactId>
8894
</plugin>
8995
</plugins>
9096
</build>

ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ private long _getLongValue() throws IOException {
414414
try {
415415
if (this.getNumberType() == NumberType.BIG_INTEGER) {
416416
BigInteger bigInteger = _reader.bigIntegerValue();
417-
if (BI_MIN_INT.compareTo(bigInteger) > 0 || BI_MAX_INT.compareTo(bigInteger) < 0) {
418-
this.reportOverflowLong();
417+
if (BI_MIN_LONG.compareTo(bigInteger) > 0 || BI_MAX_LONG.compareTo(bigInteger) < 0) {
418+
reportOverflowLong();
419419
}
420420
return bigInteger.longValue();
421421
} else {

ion/src/test/java/com/fasterxml/jackson/dataformat/ion/IonNumberOverflowTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.hamcrest.Matchers;
66
import org.junit.jupiter.api.Test;
77

8+
import com.fasterxml.jackson.core.JsonParser;
9+
import com.fasterxml.jackson.core.JsonToken;
810
import com.fasterxml.jackson.core.exc.InputCoercionException;
911

1012
import static org.hamcrest.MatcherAssert.assertThat;
@@ -72,4 +74,15 @@ private void _testLongCoercionFail(BigInteger input) throws Exception
7274
}
7375
}
7476

77+
// [dataformats-binary#569]: incorrect overflow fail for long values (from BigInteger)
78+
@Test
79+
public void testLongAsBigIntegerSize() throws Exception {
80+
// Note: Values: Long.MAX_VALUE through Long.MAX_VALUE -7 are considered LONG by Ion.
81+
BigInteger bigIntLongValue = new BigInteger(Long.MAX_VALUE + "").subtract(BigInteger.TEN);
82+
IonParser bigIntLongParser = (IonParser) new IonFactory().createParser(bigIntLongValue.toString());
83+
assertEquals(JsonToken.VALUE_NUMBER_INT, bigIntLongParser.nextToken());
84+
assertEquals(JsonParser.NumberType.BIG_INTEGER, bigIntLongParser.getNumberType());
85+
assertEquals(JsonParser.NumberTypeFP.UNKNOWN, bigIntLongParser.getNumberTypeFP());
86+
assertEquals(bigIntLongValue.longValue(), bigIntLongParser.getLongValue());
87+
}
7588
}

0 commit comments

Comments
 (0)