Skip to content
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

Merged

Conversation

arturowczarek
Copy link
Contributor

@arturowczarek arturowczarek commented Apr 22, 2023

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:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

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.

@arturowczarek arturowczarek requested a review from a team as a code owner April 22, 2023 09:41
@arturowczarek arturowczarek requested a review from Neenu1995 April 22, 2023 09:41
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigquerystorage Issues related to the googleapis/java-bigquerystorage API. labels Apr 22, 2023
@arturowczarek arturowczarek changed the title Json to proto message refactoring refactor: Json to proto message refactoring Apr 22, 2023
@@ -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;
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to inline only DONT_ACCEPT_UNKNOWN_FIELDS or ROOT_JSON_SCOPE too?
What IDE do you use? I thought all of them display the names of the parameters where constants are used. See the screenshot:
Screenshot 2023-04-27 at 19 30 11

Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@Neenu1995 Neenu1995 added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels May 1, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label May 1, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 1, 2023
@gcf-owl-bot gcf-owl-bot bot requested a review from a team as a code owner May 1, 2023 17:25
@arturowczarek arturowczarek force-pushed the json_to_proto_message_refactoring branch from b832cd7 to abea73c Compare May 2, 2023 06:15
@arturowczarek arturowczarek force-pushed the json_to_proto_message_refactoring branch from abea73c to ef24980 Compare May 2, 2023 06:16
@arturowczarek arturowczarek requested a review from yirutang May 2, 2023 06:17
@arturowczarek arturowczarek force-pushed the json_to_proto_message_refactoring branch from ef24980 to 009ced0 Compare May 2, 2023 07:35
@Neenu1995 Neenu1995 added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels May 3, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label May 3, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 3, 2023
@Neenu1995 Neenu1995 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 3, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 3, 2023
@yirutang yirutang merged commit bcd7fc9 into googleapis:main May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquerystorage Issues related to the googleapis/java-bigquerystorage API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JsonToProtoMessage refactoring
4 participants