@@ -25,6 +25,8 @@ public abstract class AvroSchemaHelper
25
25
{
26
26
/**
27
27
* Dedicated mapper for handling default values (String <-> JsonNode <-> Object)
28
+ *
29
+ * @since 2.11
28
30
*/
29
31
private static final ObjectMapper DEFAULT_VALUE_MAPPER = new ObjectMapper ();
30
32
@@ -341,7 +343,9 @@ public static String getFullName(Schema schema) {
341
343
return namespace + name ;
342
344
}
343
345
StringBuilder sb = new StringBuilder (1 + namespace .length () + name .length ());
344
- // Check if this is a nested class
346
+ // 28-Feb-2020: [dataformats-binary#195] somewhat complicated logic of trying
347
+ // to support differences between avro-lib 1.8 and 1.9...
348
+ // Check if this is a nested class
345
349
String nestedClassName = sb .append (namespace ).append ('$' ).append (name ).toString ();
346
350
try {
347
351
Class .forName (nestedClassName );
@@ -356,11 +360,17 @@ public static String getFullName(Schema schema) {
356
360
}
357
361
}
358
362
359
- public static JsonNode parseDefaultValue (Object defaultValue ) {
363
+ /**
364
+ * @since 2.11
365
+ */
366
+ public static JsonNode objectToJsonNode (Object defaultValue ) {
360
367
return DEFAULT_VALUE_MAPPER .convertValue (defaultValue , JsonNode .class );
361
368
}
362
369
363
- public static Object convertDefaultValueToObject (JsonNode defaultJsonValue ) {
370
+ /**
371
+ * @since 2.11
372
+ */
373
+ public static Object jsonNodeToObject (JsonNode defaultJsonValue ) {
364
374
return DEFAULT_VALUE_MAPPER .convertValue (defaultJsonValue , Object .class );
365
375
}
366
376
@@ -370,6 +380,8 @@ public static Object convertDefaultValueToObject(JsonNode defaultJsonValue) {
370
380
* @param defaultValue The default value to parse, in the form of a JSON string
371
381
* @return a parsed JSON representation of the default value
372
382
* @throws JsonMappingException If {@code defaultValue} is not valid JSON
383
+ *
384
+ * @since 2.11
373
385
*/
374
386
public static JsonNode parseDefaultValue (String defaultValue ) throws JsonMappingException {
375
387
if (defaultValue == null ) {
@@ -378,6 +390,9 @@ public static JsonNode parseDefaultValue(String defaultValue) throws JsonMapping
378
390
try {
379
391
return DEFAULT_VALUE_MAPPER .readTree (defaultValue );
380
392
} catch (JsonProcessingException e ) {
393
+ if (e instanceof JsonMappingException ) {
394
+ throw (JsonMappingException ) e ;
395
+ }
381
396
throw new JsonMappingException (null , "Failed to parse default value" , e );
382
397
}
383
398
}
0 commit comments