-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
AVRO-3138: Reflect data get fields support not order by property name #2581
base: main
Are you sure you want to change the base?
Conversation
I wonder if this should be an annotation on the class, instead. A Java code generator could then automatically add the annotation if needed. |
@nielsbasjes cc |
Hello! I've added AVRO-3138 as the relevant JIRA for this feature. There's a bit of discussion about why we sort the field names. It looks like you're implementing "A JVM system property ... triggers the old behaviour", but there are other possibilities for specifying this. In this case, it's possible for your test to fail depending on the JVM being used to run it. |
I have gone through the context. In most projects, they will use Java Reflect to get the fields without order, which means if the user uses Avro and other projects together, and the data is related with the avro and other projects, it may cause the problem that I meet. |
I would like to supply a config to control it instead of jvm properties. |
@RyanSkraba Use a final property to control the behavior. |
lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
Outdated
Show resolved
Hide resolved
lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectData.java
Outdated
Show resolved
Hide resolved
Rename all occurrences instead of only one.
@opwvhk , @horizonzy , Any tentative date to be merged this PR. This sorting part completely blocked multiple projects to upgrade the avro version. Any help will be appreciated. TIA! |
Field[] declaredFields = Meta.class.getDeclaredFields(); | ||
for (int i = 0; i < declaredFields.length; i++) { | ||
assertEquals(fields.get(i).name(), declaredFields[i].getName()); | ||
} |
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.
👍
In some cases, we hope that the reflect fields order maintain the original order.
At client, it create Pojo and serialize it using JSON format.
The json:
And then, create the schema using refelct data, the fields will be ordered.
The schema:
Then push the payload and schema to server, the server store the json payload as k,v format, and store the schema to the schema registry.
At another client, it want to read the data. Then the server read the k,v format data, then decode it according the schema from schema registry. But the fields order is not match the origin. So the decode json will be like
I want to make the json fields order maintain the original order, when creating the schema using ReflectData, not order the fields.