Skip to content

Commit e0bf9eb

Browse files
committed
Fixed #58
1 parent c6c1f97 commit e0bf9eb

14 files changed

+138
-27
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ public static boolean isStringable(AnnotatedClass type) {
8080
protected static String getNamespace(JavaType type) {
8181
Class<?> cls = type.getRawClass();
8282
// 16-Feb-2017, tatu: Fixed as suggested by `baharclerode@github`
83+
// 09-Mar-2016, tatu: Alas, need to undo for 2.8.8; will be in 2.9
84+
/*
8385
Class<?> enclosing = cls.getEnclosingClass();
8486
if (enclosing != null) {
8587
return enclosing.getName() + "$";
8688
}
89+
*/
8790
Package pkg = cls.getPackage();
8891
return (pkg == null) ? "" : pkg.getName();
8992
}

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

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.apache.avro.io.EncoderFactory;
1616
import org.apache.avro.reflect.ReflectData;
1717

18-
import com.fasterxml.jackson.core.JsonProcessingException;
1918
import com.fasterxml.jackson.databind.JavaType;
2019
import com.fasterxml.jackson.databind.JsonMappingException;
2120
import com.fasterxml.jackson.dataformat.avro.AvroMapper;
@@ -38,7 +37,7 @@ public byte[] apply(Schema schema, Object originalObject) {
3837
/**
3938
* Functor of {@link #getJacksonSchema(Type)}
4039
*/
41-
public static final Function<Type, Schema> getJacksonSchema = new Function<Type, Schema>() {
40+
public static final Function<Type, Schema> getJacksonSchema = new Function<Type, Schema>() {
4241
@Override
4342
public Schema apply(Type input) {
4443
return getJacksonSchema(input);
@@ -48,7 +47,7 @@ public Schema apply(Type input) {
4847
* Functor of {@link #jacksonDeserialize(Schema, Type, byte[])} which uses {@link Object} as the target type,
4948
* requiring the use of native type IDs
5049
*/
51-
public static final BiFunction<Schema, byte[], Object> jacksonDeserializer = new BiFunction<Schema, byte[], Object>() {
50+
public static final BiFunction<Schema, byte[], Object> jacksonDeserializer = new BiFunction<Schema, byte[], Object>() {
5251
@Override
5352
public Object apply(Schema schema, byte[] originalObject) {
5453
return jacksonDeserialize(schema, Object.class, originalObject);
@@ -57,7 +56,7 @@ public Object apply(Schema schema, byte[] originalObject) {
5756
/**
5857
* Functor of {@link #getApacheSchema(Type)}
5958
*/
60-
public static final Function<Type, Schema> getApacheSchema = new Function<Type, Schema>() {
59+
public static final Function<Type, Schema> getApacheSchema = new Function<Type, Schema>() {
6160
@Override
6261
public Schema apply(Type input) {
6362
return getApacheSchema(input);
@@ -66,7 +65,7 @@ public Schema apply(Type input) {
6665
/**
6766
* Functor of {@link #apacheDeserialize(Schema, byte[])}
6867
*/
69-
public static final BiFunction<Schema, byte[], Object> apacheDeserializer = new BiFunction<Schema, byte[], Object>() {
68+
public static final BiFunction<Schema, byte[], Object> apacheDeserializer = new BiFunction<Schema, byte[], Object>() {
7069
@Override
7170
public Object apply(Schema first, byte[] second) {
7271
return apacheDeserialize(first, second);
@@ -75,7 +74,7 @@ public Object apply(Schema first, byte[] second) {
7574
/**
7675
* Functor of {@link #apacheSerialize(Schema, Object)}
7776
*/
78-
public static final BiFunction<Schema, Object, byte[]> apacheSerializer = new BiFunction<Schema, Object, byte[]>() {
77+
public static final BiFunction<Schema, Object, byte[]> apacheSerializer = new BiFunction<Schema, Object, byte[]>() {
7978
@Override
8079
public byte[] apply(Schema schema, Object originalObject) {
8180
return apacheSerialize(schema, originalObject);
@@ -93,8 +92,7 @@ public byte[] apply(Schema schema, Object originalObject) {
9392
@SuppressWarnings({"unchecked", "SuspiciousMethodCalls", "rawtypes"})
9493
@Override
9594
protected Schema createSchema(Type type, Map<String, Schema> names) {
96-
/*
97-
* 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
9896
* keys. To persist and look up type variable information, we watch for ParameterizedTypes, TypeVariables, and Classes with
9997
* generic superclasses to extract type variable information and store it in the map. This allows full type variable resolution
10098
* when building a schema from reflection data.

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

+39-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
import com.fasterxml.jackson.annotation.JsonProperty;
77

8-
import lombok.AllArgsConstructor;
9-
import lombok.Data;
10-
import lombok.NoArgsConstructor;
118
import org.apache.avro.Schema;
9+
import org.junit.Assume;
1210
import org.junit.runner.RunWith;
1311
import org.junit.runners.Parameterized;
1412

@@ -20,7 +18,22 @@
2018
* interoperability between the implementations.
2119
*/
2220
@RunWith(Parameterized.class)
23-
public abstract class InteropTestBase {
21+
public abstract class InteropTestBase
22+
{
23+
// To work around 2.8/2.9 difference wrt namespaces for enums
24+
// See [dataformats-binary#58] for details
25+
protected void assumeCompatibleNsForDeser() {
26+
Assume.assumeTrue(deserializeFunctor != ApacheAvroInteropUtil.apacheDeserializer
27+
|| schemaFunctor != ApacheAvroInteropUtil.getJacksonSchema);
28+
}
29+
30+
// To work around 2.8/2.9 difference wrt namespaces for enums
31+
// See [dataformats-binary#58] for details
32+
protected void assumeCompatibleNsForSer() {
33+
Assume.assumeTrue(serializeFunctor != ApacheAvroInteropUtil.apacheSerializer
34+
|| schemaFunctor != ApacheAvroInteropUtil.getJacksonSchema);
35+
}
36+
2437
/**
2538
* Helper method for building a {@link ParameterizedType} for use with {@link #roundTrip(Type, Object)}
2639
*
@@ -155,13 +168,32 @@ public enum DummyEnum {
155168
NORTH, SOUTH, EAST, WEST
156169
}
157170

158-
@Data
159-
@NoArgsConstructor
160-
@AllArgsConstructor
161171
public static class DummyRecord {
162172
@JsonProperty(required = true)
163173
private String firstValue;
164174
@JsonProperty(required = true)
165175
private int secondValue;
176+
177+
public DummyRecord(String f, int s) {
178+
firstValue = f;
179+
secondValue = s;
180+
}
181+
protected DummyRecord() { }
182+
183+
public String getFirstValue() { return firstValue; }
184+
public int getSecondValue() { return secondValue; }
185+
186+
@Override
187+
public boolean equals(Object o) {
188+
if (o == null || !(o instanceof DummyRecord)) return false;
189+
DummyRecord other = (DummyRecord) o;
190+
if (other.secondValue == secondValue) {
191+
if (firstValue == null) {
192+
return other.firstValue == null;
193+
}
194+
return firstValue.equals(other.firstValue);
195+
}
196+
return false;
197+
}
166198
}
167199
}

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
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

11+
import com.fasterxml.jackson.dataformat.avro.interop.InteropTestBase;
12+
1013
public class AvroIgnoreTest extends InteropTestBase
1114
{
1215
static class RecordWithIgnoredField {
@@ -18,6 +21,12 @@ public RecordWithIgnoredField() {}
1821

1922
}
2023

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

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

+7-1
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;
@@ -32,6 +32,12 @@ public static class RecordWithNameCollision {
3232
public String otherField;
3333
}
3434

35+
@Before
36+
public void setup() {
37+
// 2.8 doesn't generate schemas with compatible namespaces for Apache deserializer
38+
assumeCompatibleNsForDeser();
39+
}
40+
3541
@Test
3642
public void testRecordWithRenamedField() {
3743
RecordWithRenamed original = new RecordWithRenamed();

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.List;
66
import java.util.Map;
77

8+
import org.junit.Before;
89
import org.junit.Test;
910

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

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.*;
44

5+
import org.junit.Before;
56
import org.junit.Test;
67

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

1724
@Test
1825
public void testMapWithRecordValues() {

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import lombok.RequiredArgsConstructor;
1111
import lombok.ToString;
1212
import org.apache.avro.reflect.Nullable;
13+
import org.junit.Before;
1314
import org.junit.Test;
1415

1516
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -21,7 +22,8 @@
2122
/**
2223
* Tests records involving complex value types (Lists, Records, Maps, Enums)
2324
*/
24-
public class RecordWithComplexTest extends InteropTestBase {
25+
public class RecordWithComplexTest extends InteropTestBase
26+
{
2527
@Data
2628
@ToString(callSuper = true)
2729
@EqualsAndHashCode(callSuper = true)
@@ -43,6 +45,13 @@ public RecursiveDummyRecord(String firstValue, Integer secondValue, DummyRecord
4345
}
4446
}
4547

48+
@Before
49+
public void setup() {
50+
// 2.8 doesn't generate schemas with compatible namespaces for Apache deserializer
51+
assumeCompatibleNsForDeser();
52+
assumeCompatibleNsForSer();
53+
}
54+
4655
@Test
4756
public void testEmptyRecordWithRecordValues() {
4857
Map<String, DummyRecord> original = new HashMap<>();

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

+10-1
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;
@@ -10,7 +12,14 @@
1012
/**
1113
* Tests serializing primitive array fields on records
1214
*/
13-
public class RecordWithPrimitiveArrayTest extends InteropTestBase {
15+
public class RecordWithPrimitiveArrayTest extends InteropTestBase
16+
{
17+
@Before
18+
public void setup() {
19+
// 2.8 doesn't generate schemas with compatible namespaces for Apache deserializer
20+
assumeCompatibleNsForDeser();
21+
}
22+
1423
@Data
1524
public static class TestRecord {
1625
private byte[] byteArrayField = new byte[0];

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

+10-1
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;
@@ -10,7 +12,8 @@
1012
/**
1113
* Tests serializing primitive fields on records
1214
*/
13-
public class RecordWithPrimitiveTest extends InteropTestBase {
15+
public class RecordWithPrimitiveTest extends InteropTestBase
16+
{
1417
@Data
1518
public static class TestRecord {
1619
private byte byteField;
@@ -22,6 +25,12 @@ public static class TestRecord {
2225
private double doubleField;
2326
}
2427

28+
@Before
29+
public void setup() {
30+
// 2.8 doesn't generate schemas with compatible namespaces for Apache deserializer
31+
assumeCompatibleNsForDeser();
32+
}
33+
2534
@Test
2635
public void testByteField() {
2736
TestRecord record = new TestRecord();

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

+10-1
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;
@@ -10,7 +12,8 @@
1012
/**
1113
* Tests serializing primitive array fields on records
1214
*/
13-
public class RecordWithPrimitiveWrapperArrayTest extends InteropTestBase {
15+
public class RecordWithPrimitiveWrapperArrayTest extends InteropTestBase
16+
{
1417
@Data
1518
public static class TestRecord {
1619
private Byte[] byteArrayField = new Byte[0];
@@ -23,6 +26,12 @@ public static class TestRecord {
2326
private String[] stringArrayField = new String[0];
2427
}
2528

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

0 commit comments

Comments
 (0)