@@ -88,7 +88,10 @@ public static boolean isStringable(AnnotatedClass type) {
88
88
}
89
89
90
90
protected static String getNamespace (JavaType type ) {
91
- Class <?> cls = type .getRawClass ();
91
+ return getNamespace (type .getRawClass ());
92
+ }
93
+
94
+ protected static String getNamespace (Class <?> cls ) {
92
95
// 16-Feb-2017, tatu: Fixed as suggested by `baharclerode@github`;
93
96
// NOTE: was reverted in 2.8.8, but is enabled for Jackson 2.9.
94
97
Class <?> enclosing = cls .getEnclosingClass ();
@@ -100,7 +103,11 @@ protected static String getNamespace(JavaType type) {
100
103
}
101
104
102
105
protected static String getName (JavaType type ) {
103
- String name = type .getRawClass ().getSimpleName ();
106
+ return getName (type .getRawClass ());
107
+ }
108
+
109
+ protected static String getName (Class <?> cls ) {
110
+ String name = cls .getSimpleName ();
104
111
// Alas, some characters not accepted...
105
112
while (name .indexOf ("[]" ) >= 0 ) {
106
113
name = name .replace ("[]" , "Array" );
@@ -142,6 +149,10 @@ public static Schema simpleSchema(JsonFormatTypes type, JavaType hint)
142
149
}
143
150
return Schema .create (Schema .Type .DOUBLE );
144
151
case STRING :
152
+ // 26-Nov-2019, tatu: [dataformats-binary#179] UUIDs are special
153
+ if ((hint != null ) && hint .hasRawClass (java .util .UUID .class )) {
154
+ return createUUIDSchema ();
155
+ }
145
156
return Schema .create (Schema .Type .STRING );
146
157
case ARRAY :
147
158
case OBJECT :
@@ -249,6 +260,17 @@ public static Schema createEnumSchema(BeanDescription bean, List<String> values)
249
260
), bean );
250
261
}
251
262
263
+ /**
264
+ * Helper method to enclose details of expressing best Avro Schema for
265
+ * {@link java.util.UUID}: 16-byte fixed-length binary (alternative would
266
+ * be basic variable length "bytes").
267
+ *
268
+ * @since 2.11
269
+ */
270
+ public static Schema createUUIDSchema () {
271
+ return Schema .createFixed ("UUID" , "" , "java.util" , 16 );
272
+ }
273
+
252
274
/**
253
275
* Looks for {@link AvroAlias @AvroAlias} on {@code bean} and adds it to {@code schema} if it exists
254
276
* @param schema Schema to which the alias should be added
0 commit comments