[ZEPPELIN-6309] Improve method by replacing JsonObject parameter #5063
[nitpick] Consider using ArrayList constructor with initial capacity or LinkedList to match the pattern used in the convertPermissionsFromUsersToOwners method where LinkedList is used for owners.
List<String> users = null;
if (jsonObject != null) {
JsonObject option = jsonObject.getAsJsonObject("option");
if (option != null) {
JsonArray usersArray = option.getAsJsonArray("users");
if (usersArray != null) {
users = new ArrayList<>(usersArray.size());
for (JsonElement userElement : usersArray) {
users.add(userElement.getAsString());
}
}
}
}
return users == null ? new ArrayList<>() : users;
[nitpick] The import statement should be placed in alphabetical order with other java.util imports to maintain consistent import organization.
import java.util.List;
Pull Request Overview
This PR refactors the convertPermissionsFromUsersToOwners method in InterpreterSetting.java by removing the JsonObject parameter and separating JSON parsing logic from business logic, addressing a TODO comment about "ugly code".
extractUsersFromJsonObjectList<String> instead of JsonObjectReviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
| ---- | ----------- |
| InterpreterSetting.java | Refactored main method and added new static helper method for JSON parsing |
| ConfigStorage.java | Updated caller to use new method signature with extracted users list |
| InterpreterInfoSaving.java | Updated caller to use new method signature with extracted users list |
---
<sub>Tip: Customize your code reviews with copilot-instructions.md. <a href="/apache/zeppelin/new/master/.github?filename=copilot-instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Create the file</a> or <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">learn how to get started</a>.</sub>
Good catch! Updated to use LinkedList for consistency with the rest of the class. This maintains consistency with the owners field initialization on line.
Are you sure this is what is meant by “ugly” here?
I think we should use GSON here to create objects directly.
GSON.fromJson(json, myFanceClass.class);
Are you sure this is what is meant by “ugly” here? I think we should use GSON here to create objects directly.
>> GSON.fromJson(json, myFanceClass.class); >
Thank you for the feedback! You're absolutely right. I've refactored the code to use GSON.fromJson() directly
instead of JsonObject parameter.
LGTM 👍
Merged into master and branch-0.12
ParkGyeongTae
celinayk
What is this PR for?
Refactored the
convertPermissionsFromUsersToOwnersmethod in InterpreterSetting.java to improve code readability and maintainability by separating JSON parsing logic from business logic, addressing the TODO comment that identified this as "ugly code".What type of PR is it?
Refactoring
Todos
[x] - Refactor convertPermissionsFromUsersToOwners method to remove JsonObject parameter
[x] - Extract JSON parsing logic into separate static helper method
[x] - Update all callers to use new method signature
What is the Jira issue?
ZEPPELIN-6309
How should this be tested?
Screenshots (if appropriate)
Questions:
Does the license files need to update? No
Is there breaking changes for older versions? No
Does this needs documentation? No