Skip to content

Commit d9d6e60

Browse files
committed
Merge branch '2.8'
2 parents 56e053c + e0bf9eb commit d9d6e60

File tree

14 files changed

+129
-27
lines changed

14 files changed

+129
-27
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@ public static boolean isStringable(AnnotatedClass type) {
7979

8080
protected static String getNamespace(JavaType type) {
8181
Class<?> cls = type.getRawClass();
82-
// 16-Feb-2017, tatu: Fixed as suggested by `baharclerode@github`
82+
// 16-Feb-2017, tatu: Fixed as suggested by `baharclerode@github`;
83+
// NOTE: was revert in 2.8.8, but is enabled for Jackson 2.9.
8384
Class<?> enclosing = cls.getEnclosingClass();
8485
if (enclosing != null) {
8586
return enclosing.getName() + "$";
8687
}
8788
Package pkg = cls.getPackage();
8889
return (pkg == null) ? "" : pkg.getName();
8990
}
90-
91+
9192
protected static String getName(JavaType type) {
9293
String name = type.getRawClass().getSimpleName();
9394
// Alas, some characters not accepted...
@@ -96,7 +97,7 @@ protected static String getName(JavaType type) {
9697
}
9798
return name;
9899
}
99-
100+
100101
protected static Schema unionWithNull(Schema otherSchema)
101102
{
102103
List<Schema> schemas = new ArrayList<Schema>();

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/ApacheAvroInteropUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ public byte[] apply(Schema schema, Object originalObject) throws IOException {
9292
@SuppressWarnings({"unchecked", "SuspiciousMethodCalls", "rawtypes"})
9393
@Override
9494
protected Schema createSchema(Type type, Map<String, Schema> names) {
95-
/*
96-
* Note, we abuse the fact that we can stick whatever we want into "names" and it won't interfere as long as we don't use String
95+
/* Note, we abuse the fact that we can stick whatever we want into "names" and it won't interfere as long as we don't use String
9796
* keys. To persist and look up type variable information, we watch for ParameterizedTypes, TypeVariables, and Classes with
9897
* generic superclasses to extract type variable information and store it in the map. This allows full type variable resolution
9998
* when building a schema from reflection data.

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/InteropTestBase.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,45 @@
55
import java.lang.reflect.Type;
66

77
import org.apache.avro.Schema;
8+
import org.junit.Assume;
89
import org.junit.runner.RunWith;
910
import org.junit.runners.Parameterized;
1011

11-
import static com.fasterxml.jackson.dataformat.avro.interop.ApacheAvroInteropUtil.*;
12+
import static com.fasterxml.jackson.dataformat.avro.interop.ApacheAvroInteropUtil.apacheDeserializer;
13+
import static com.fasterxml.jackson.dataformat.avro.interop.ApacheAvroInteropUtil.apacheSerializer;
14+
import static com.fasterxml.jackson.dataformat.avro.interop.ApacheAvroInteropUtil.jacksonDeserializer;
15+
import static com.fasterxml.jackson.dataformat.avro.interop.ApacheAvroInteropUtil.jacksonSerializer;
16+
import static com.fasterxml.jackson.dataformat.avro.interop.ApacheAvroInteropUtil.getApacheSchema;
17+
import static com.fasterxml.jackson.dataformat.avro.interop.ApacheAvroInteropUtil.getJacksonSchema;
18+
import static com.fasterxml.jackson.dataformat.avro.interop.ApacheAvroInteropUtil.Function;
19+
import static com.fasterxml.jackson.dataformat.avro.interop.ApacheAvroInteropUtil.BiFunction;
1220

1321
/**
1422
* Parameterized base class for tests that populates {@link #schemaFunctor}, {@link #serializeFunctor}, and
1523
* {@link #deserializeFunctor} with permutations of Apache and Jackson implementations to test all aspects of
1624
* interoperability between the implementations.
1725
*/
1826
@RunWith(Parameterized.class)
19-
public abstract class InteropTestBase {
27+
public abstract class InteropTestBase
28+
{
29+
public enum DummyEnum {
30+
NORTH, SOUTH, EAST, WEST
31+
}
32+
33+
// To work around 2.8/2.9 difference wrt namespaces for enums
34+
// See [dataformats-binary#58] for details
35+
protected void assumeCompatibleNsForDeser() {
36+
Assume.assumeTrue(deserializeFunctor != apacheDeserializer
37+
|| schemaFunctor != ApacheAvroInteropUtil.getJacksonSchema);
38+
}
39+
40+
// To work around 2.8/2.9 difference wrt namespaces for enums
41+
// See [dataformats-binary#58] for details
42+
protected void assumeCompatibleNsForSer() {
43+
Assume.assumeTrue(serializeFunctor != apacheSerializer
44+
|| schemaFunctor != ApacheAvroInteropUtil.getJacksonSchema);
45+
}
46+
2047
/**
2148
* Helper method for building a {@link ParameterizedType} for use with {@link #roundTrip(Type, Object)}
2249
*
@@ -85,13 +112,13 @@ public String toString() {
85112
}
86113

87114
@Parameterized.Parameter
88-
public Function<Type, Schema> schemaFunctor;
115+
public Function<Type, Schema> schemaFunctor;
89116
@Parameterized.Parameter(1)
90117
public BiFunction<Schema, Object, byte[]> serializeFunctor;
91118
@Parameterized.Parameter(2)
92119
public BiFunction<Schema, byte[], Object> deserializeFunctor;
93120
@Parameterized.Parameter(3)
94-
public String combinationName;
121+
public String combinationName;
95122

96123
@Parameterized.Parameters(name = "{3}")
97124
public static Object[][] getParameters() {
@@ -141,13 +168,9 @@ protected <T> T roundTrip(T object) throws IOException {
141168
protected <T> T roundTrip(Type schemaType, T object) throws IOException {
142169
Schema schema = schemaFunctor.apply(schemaType);
143170
// Temporary hack until jackson supports native type Ids and we don't need to give it a target type
144-
if (deserializeFunctor == jacksonDeserializer) {
145-
return jacksonDeserialize(schema, schemaType, serializeFunctor.apply(schema, object));
171+
if (deserializeFunctor == ApacheAvroInteropUtil.jacksonDeserializer) {
172+
return ApacheAvroInteropUtil.jacksonDeserialize(schema, schemaType, serializeFunctor.apply(schema, object));
146173
}
147174
return (T) deserializeFunctor.apply(schema, serializeFunctor.apply(schema, object));
148175
}
149-
150-
public enum DummyEnum {
151-
NORTH, SOUTH, EAST, WEST
152-
}
153176
}

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/annotations/AvroIgnoreTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.fasterxml.jackson.dataformat.avro.interop.annotations;
22

3-
import com.fasterxml.jackson.dataformat.avro.interop.InteropTestBase;
43
import org.apache.avro.reflect.AvroIgnore;
4+
import org.junit.Before;
55
import org.junit.Test;
66

77
import static org.hamcrest.CoreMatchers.*;
8+
89
import static org.junit.Assert.assertThat;
910

1011
import java.io.IOException;
1112

13+
import com.fasterxml.jackson.dataformat.avro.interop.InteropTestBase;
14+
1215
public class AvroIgnoreTest extends InteropTestBase
1316
{
1417
static class RecordWithIgnoredField {
@@ -19,6 +22,12 @@ public RecordWithIgnoredField() {}
1922
public String notIgnoredField;
2023
}
2124

25+
@Before
26+
public void setup() {
27+
// 2.8 doesn't generate schemas with compatible namespaces for Apache deserializer
28+
assumeCompatibleNsForDeser();
29+
}
30+
2231
@Test
2332
public void testFieldIgnored() throws IOException {
2433
RecordWithIgnoredField r = new RecordWithIgnoredField();

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/annotations/AvroNameTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.fasterxml.jackson.dataformat.avro.interop.InteropTestBase;
55

66
import org.apache.avro.reflect.AvroName;
7-
7+
import org.junit.Before;
88
import org.junit.Test;
99

1010
import static org.assertj.core.api.Assertions.assertThat;
@@ -34,6 +34,12 @@ public static class RecordWithNameCollision {
3434
public String otherField;
3535
}
3636

37+
@Before
38+
public void setup() {
39+
// 2.8 doesn't generate schemas with compatible namespaces for Apache deserializer
40+
assumeCompatibleNsForDeser();
41+
}
42+
3743
@Test
3844
public void testRecordWithRenamedField() throws IOException{
3945
RecordWithRenamed original = new RecordWithRenamed();

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/arrays/ListWithComplexTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.List;
77
import java.util.Map;
88

9+
import org.junit.Before;
910
import org.junit.Test;
1011

1112
import com.fasterxml.jackson.dataformat.avro.interop.DummyRecord;
@@ -17,7 +18,14 @@
1718
/**
1819
* Tests lists involving complex element types (Lists, Records, Maps, Enums)
1920
*/
20-
public class ListWithComplexTest extends InteropTestBase {
21+
public class ListWithComplexTest extends InteropTestBase
22+
{
23+
@Before
24+
public void setup() {
25+
// 2.8 doesn't generate schemas with compatible namespaces for Apache deserializer
26+
assumeCompatibleNsForDeser();
27+
}
28+
2129
@Test
2230
public void testEmptyListWithRecordElements() throws IOException {
2331
List<DummyRecord> original = new ArrayList<>();

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/maps/MapWithComplexTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.util.*;
55

6+
import org.junit.Before;
67
import org.junit.Test;
78

89
import com.fasterxml.jackson.dataformat.avro.interop.DummyRecord;
@@ -14,7 +15,13 @@
1415
/**
1516
* Tests Maps involving complex value types (Lists, Records, Maps, Enums)
1617
*/
17-
public class MapWithComplexTest extends InteropTestBase {
18+
public class MapWithComplexTest extends InteropTestBase
19+
{
20+
@Before
21+
public void setup() {
22+
// 2.8 doesn't generate schemas with compatible namespaces for Apache deserializer
23+
assumeCompatibleNsForDeser();
24+
}
1825

1926
@Test
2027
public void testMapWithRecordValues() throws IOException {

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/records/RecordWithComplexTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.Map;
66

77
import org.apache.avro.AvroTypeException;
8+
9+
import org.junit.Before;
810
import org.junit.Test;
911

1012
import com.fasterxml.jackson.databind.JsonMappingException;
@@ -17,7 +19,15 @@
1719
/**
1820
* Tests records involving complex value types (Lists, Records, Maps, Enums)
1921
*/
20-
public class RecordWithComplexTest extends InteropTestBase {
22+
public class RecordWithComplexTest extends InteropTestBase
23+
{
24+
@Before
25+
public void setup() {
26+
// 2.8 doesn't generate schemas with compatible namespaces for Apache deserializer
27+
assumeCompatibleNsForDeser();
28+
assumeCompatibleNsForSer();
29+
}
30+
2131
@Test
2232
public void testEmptyRecordWithRecordValues() throws IOException {
2333
Map<String, DummyRecord> original = new HashMap<>();

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/records/RecordWithPrimitiveArrayTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.fasterxml.jackson.dataformat.avro.interop.records;
22

33
import lombok.Data;
4+
5+
import org.junit.Before;
46
import org.junit.Test;
57

68
import com.fasterxml.jackson.dataformat.avro.interop.InteropTestBase;
@@ -12,7 +14,14 @@
1214
/**
1315
* Tests serializing primitive array fields on records
1416
*/
15-
public class RecordWithPrimitiveArrayTest extends InteropTestBase {
17+
public class RecordWithPrimitiveArrayTest extends InteropTestBase
18+
{
19+
@Before
20+
public void setup() {
21+
// 2.8 doesn't generate schemas with compatible namespaces for Apache deserializer
22+
assumeCompatibleNsForDeser();
23+
}
24+
1625
@Data
1726
public static class TestRecord {
1827
private byte[] byteArrayField = new byte[0];

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/records/RecordWithPrimitiveTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.fasterxml.jackson.dataformat.avro.interop.records;
22

33
import lombok.Data;
4+
5+
import org.junit.Before;
46
import org.junit.Test;
57

68
import com.fasterxml.jackson.dataformat.avro.interop.InteropTestBase;
@@ -12,7 +14,8 @@
1214
/**
1315
* Tests serializing primitive fields on records
1416
*/
15-
public class RecordWithPrimitiveTest extends InteropTestBase {
17+
public class RecordWithPrimitiveTest extends InteropTestBase
18+
{
1619
@Data
1720
public static class TestRecord {
1821
private byte byteField;
@@ -24,6 +27,12 @@ public static class TestRecord {
2427
private double doubleField;
2528
}
2629

30+
@Before
31+
public void setup() {
32+
// 2.8 doesn't generate schemas with compatible namespaces for Apache deserializer
33+
assumeCompatibleNsForDeser();
34+
}
35+
2736
@Test
2837
public void testByteField() throws IOException {
2938
TestRecord record = new TestRecord();

0 commit comments

Comments
 (0)