-
Notifications
You must be signed in to change notification settings - Fork 85
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
refactor: Json to proto message refactoring #2085
refactor: Json to proto message refactoring #2085
Conversation
@@ -102,8 +99,10 @@ public class JsonToProtoMessage implements ToProtoConverter<Object> { | |||
.optionalEnd() | |||
.toFormatter() | |||
.withZone(ZoneOffset.UTC); | |||
private final String ROOT_JSON_SCOPE = "root"; | |||
private final boolean DONT_ACCEPT_UNKNOWN_FIELDS = false; |
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.
It is a bit strange to have this constant. I think it is easier to read just to keep the bollean.
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.
Are you sure? It explicitly names the intention. Otherwise you may mix boolean values:
return convertToProtoMessage(protoSchema, null, json, "root", true, false);
Can you tell what is true
and false
here? Your IDE will probably help you here, but what about GitHub review? Are you sure you won't put topLevel
value in place of ignoreUnknownArguments
parameter?
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.
Usually we will just annotate the parameters with the argument name. So it is just:
protoSchema,
tableSchema.getFieldsList(),
json,
"root",
/topLevel=/ true,
/ignoreUnknownFields/ false);
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.
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.
DONT_ACCEPT_UNKNOWN_FIELDS and ROOT_JSON_SCOPE. Thanks.
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.
Done
@@ -25,13 +25,11 @@ | |||
import com.google.protobuf.Descriptors.Descriptor; |
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.
Thanks for improving the code!
Could you provide a list of things refactored in the PR description?
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.
Updated
b832cd7
to
abea73c
Compare
…d remove usage of soon deprecated (Java 9) Long constructor
…ToProtoMessage and use primitives for booleans
…sonToProtoMessage repeated fields.
abea73c
to
ef24980
Compare
… in JsonToProtoMessage
ef24980
to
009ced0
Compare
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Changes:
refactor: Use equalsIgnoreCase for JSON string boolean values in JsonToProtoMessage and use primitives for booleans
refactor: Use enhanced for in JsonToProtoMessage
refactor: Properly reference to static field INSTANCE in JsonToProtoMessage
refactor: Remove unnecessary LOG field from JsonToProtoMessage
refactor: Remove unnecessary casts from JsonToProtoMessage methods and remove usage of soon deprecated (Java 9) Long constructor
refactor: Remove unnecessary variables "message" from JsonToProtoMessage methods
refactor: Remove topLevel parameter from JsonToProtoMessage methods
refactor: Extract magic variables to constants
refactor: Capitalize deep constants in JsonToProtoMessage and make them final
Fixes #2042 ☕️
If you write sample code, please follow the samples format.