File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
main/java/com/fasterxml/jackson/dataformat/avro
test/java/com/fasterxml/jackson/dataformat/avro/schemaev Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,28 @@ public AvroSchema withReaderSchema(AvroSchema readerSchema)
90
90
return Resolving .create (w , r );
91
91
}
92
92
93
+ /**
94
+ * Similar to {@link #withReaderSchema} but will NOT verify compatibility of schemas:
95
+ * this means that certain problems (such as missing default value for a newly added
96
+ * field) that would be caught at construction may be surfaced later when using
97
+ * schema. This is, however, sometimes necessary to work around potential BUT NOT ACTUAL
98
+ * problems.
99
+ *
100
+ * @since 2.9
101
+ */
102
+ public AvroSchema withUnsafeReaderSchema (AvroSchema readerSchema )
103
+ throws JsonProcessingException
104
+ {
105
+ Schema w = _writerSchema ;
106
+ Schema r = readerSchema .getAvroSchema ();
107
+
108
+ if (r .equals (w )) {
109
+ return this ;
110
+ }
111
+ w = Schema .applyAliases (w , r );
112
+ return Resolving .create (w , r );
113
+ }
114
+
93
115
@ Override
94
116
public String getSchemaType () {
95
117
return TYPE_ID ;
Original file line number Diff line number Diff line change @@ -179,5 +179,9 @@ public void testFailNewFieldNoDefault() throws Exception
179
179
verifyException (e , "Data encoded using writer schema" );
180
180
verifyException (e , "will or may fail to decode using reader schema" );
181
181
}
182
+
183
+ // However... should be possible with unsafe alternative
184
+ AvroSchema risky = srcSchema .withUnsafeReaderSchema (dstSchema );
185
+ assertNotNull (risky );
182
186
}
183
187
}
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ Modules:
11
11
12
12
2.9.0 (not yet released)
13
13
14
+ #95: Add new method, `withUnsafeReaderSchema` in `AvroSchema` to allow avoiding verification exception
15
+
14
16
2.8.9.1 (not yet released)
15
17
16
18
#94: Should _ensureRoom in ProtobufGenerator.writeString()
You can’t perform that action at this time.
0 commit comments