-
-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support enum avro serialization with default value #391
base: 2.16
Are you sure you want to change the base?
Changes from 1 commit
736999c
9f799db
d8c4fea
9790707
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedClass; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedConstructor; | ||
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; | ||
import com.fasterxml.jackson.databind.json.JsonMapper; | ||
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; | ||
import com.fasterxml.jackson.databind.util.ClassUtil; | ||
|
@@ -71,6 +72,14 @@ public abstract class AvroSchemaHelper | |
String.class | ||
)); | ||
|
||
/** | ||
* | ||
* Jackson annotation introspector for verifying enum default annotation for Avro Schema generation | ||
* | ||
* @since 2.16 | ||
*/ | ||
private static final JacksonAnnotationIntrospector JACKSON_ANNOTATION_INTROSPECTOR = new JacksonAnnotationIntrospector(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, This just means some more plumbing of things to get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense. thanks |
||
|
||
/** | ||
* Checks if a given type is "Stringable", that is one of the default | ||
* {@code STRINGABLE_CLASSES}, is an {@code Enum}, | ||
|
@@ -269,10 +278,11 @@ public static Schema parseJsonSchema(String json) { | |
*/ | ||
public static Schema createEnumSchema(BeanDescription bean, List<String> values) { | ||
final JavaType enumType = bean.getType(); | ||
Enum<?> defaultEnumValue = JACKSON_ANNOTATION_INTROSPECTOR.findDefaultEnumValue((Class<Enum<?>>)(Class<?>) enumType.getRawClass()); | ||
return addAlias(Schema.createEnum( | ||
getName(enumType), | ||
bean.findClassDescription(), | ||
getNamespace(enumType, bean.getClassInfo()), values | ||
getNamespace(enumType, bean.getClassInfo()), values, defaultEnumValue != null ? defaultEnumValue.toString() : null | ||
), bean); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under impression that this will break about everything... did you run unit test suite?
But even if not, we need this to be in separate PR, with separate issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wary of that upgrade as well, but doing that version bump and running the avro test suite resulted in passing tests.
We're a gradle shop so running stuff with maven was a bit hokey with all our firewall rules. Readying through #167 looks like some stuff has been upgraded but I imagine there must be missing unit tests for some of the underlying avro lib changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that's odd wrt tests: for me code did not compile with missing imports.
And compilation on CI and locally did not work.
I wish I was more up to date with Avro lib changes since there are newer minor versions, some of which might resolve issues -- although from what I remember, things were quite messy wrt backwards-compatibility (lack thereof) for some specific usage.