Skip to content

Commit 205d845

Browse files
author
Piotr Rżysko
authored
Merge pull request #55 from jewertow/better-message-in-avro-conversion-exception
Add more detailed message to AvroConversionException
2 parents 30ed963 + 9fe0335 commit 205d845

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

converter/src/main/java/tech/allegro/schema/json2avro/converter/JsonGenericRecordReader.java

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public GenericData.Record read(Map<String, Object> json, Schema schema) {
5656
Deque<String> path = new ArrayDeque<>();
5757
try {
5858
return readRecord(json, schema, path);
59+
} catch (AvroTypeException ex) {
60+
throw new AvroConversionException("Failed to convert JSON to Avro: " + ex.getMessage(), ex);
5961
} catch (AvroRuntimeException ex) {
6062
throw new AvroConversionException("Failed to convert JSON to Avro", ex);
6163
}

converter/src/test/groovy/tech/allegro/schema/json2avro/converter/JsonAvroConverterSpec.groovy

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ class JsonAvroConverterSpec extends Specification {
122122
converter.convertToAvro(json.bytes, schema)
123123

124124
then:
125-
thrown AvroConversionException
125+
def e = thrown AvroConversionException
126+
e.message == "Failed to convert JSON to Avro: Field field_integer is expected to be type: java.lang.Number"
126127
}
127128

128129
def "should ignore unknown fields"() {

0 commit comments

Comments
 (0)