|
10 | 10 | import org.apache.avro.JsonProperties;
|
11 | 11 | import org.apache.avro.Schema;
|
12 | 12 | import org.apache.avro.Schema.Parser;
|
| 13 | +import org.apache.avro.SchemaParseException; |
13 | 14 | import org.apache.avro.reflect.AvroAlias;
|
14 | 15 | import org.apache.avro.reflect.Stringable;
|
15 | 16 | import org.apache.avro.specific.SpecificData;
|
@@ -269,13 +270,27 @@ public static Schema parseJsonSchema(String json) {
|
269 | 270 | * @param values List of enum names
|
270 | 271 | * @return An {@link org.apache.avro.Schema.Type#ENUM ENUM} schema.
|
271 | 272 | */
|
272 |
| - public static Schema createEnumSchema(BeanDescription bean, List<String> values) { |
| 273 | + public static Schema createEnumSchema(BeanDescription bean, List<String> values) |
| 274 | + { |
273 | 275 | final JavaType enumType = bean.getType();
|
274 |
| - return addAlias(Schema.createEnum( |
275 |
| - getName(enumType), |
276 |
| - bean.findClassDescription(), |
277 |
| - getNamespace(enumType, bean.getClassInfo()), values |
278 |
| - ), bean); |
| 276 | + final Schema avroSchema; |
| 277 | + |
| 278 | + try { |
| 279 | + avroSchema = Schema.createEnum( |
| 280 | + getName(enumType), |
| 281 | + bean.findClassDescription(), |
| 282 | + getNamespace(enumType, bean.getClassInfo()), |
| 283 | + values); |
| 284 | + } catch (SchemaParseException spe) { |
| 285 | + final String msg = String.format("Problem generating Avro `Schema` for Enum type %s: %s", |
| 286 | + ClassUtil.getTypeDescription(enumType), spe.getMessage()); |
| 287 | + |
| 288 | + // 05-Jan-2025, tatu: SHOULD be able to throw like so but |
| 289 | + // `SchemaBuilder` does not expose checked exceptions so need to |
| 290 | + // throw InvalidDefinitionException.from((JsonParser) null, msg); |
| 291 | + throw new IllegalArgumentException(msg, spe); |
| 292 | + } |
| 293 | + return addAlias(avroSchema, bean); |
279 | 294 | }
|
280 | 295 |
|
281 | 296 | /**
|
|
0 commit comments