Skip to content

Commit 7aced0e

Browse files
committed
Merge branch '2.8'
2 parents e3aa027 + 6ffc0cf commit 7aced0e

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroSchema.java

+22
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ public AvroSchema withReaderSchema(AvroSchema readerSchema)
9090
return Resolving.create(w, r);
9191
}
9292

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+
93115
@Override
94116
public String getSchemaType() {
95117
return TYPE_ID;

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/schemaev/SimpleEvolutionTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,9 @@ public void testFailNewFieldNoDefault() throws Exception
316316
verifyException(e, "Data encoded using writer schema");
317317
verifyException(e, "will or may fail to decode using reader schema");
318318
}
319+
320+
// However... should be possible with unsafe alternative
321+
AvroSchema risky = srcSchema.withUnsafeReaderSchema(dstSchema);
322+
assertNotNull(risky);
319323
}
320324
}

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Modules:
2828
(reported by Eldad R)
2929
#69 (avro): Add support for `@AvroEncode` annotation
3030
#79 (proto): Fix wire type for packed arrays
31+
#95: Add new method, `withUnsafeReaderSchema` in `AvroSchema` to allow avoiding verification exception
3132
- [avro] Upgrade `avro-core` dep from 1.7.7 to 1.8.1
3233

3334
2.8.9.1 (not yet released)

0 commit comments

Comments
 (0)