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

Add clear method to JsonArray #1667

Closed
wants to merge 1 commit into from
Closed

Add clear method to JsonArray #1667

wants to merge 1 commit into from

Conversation

LorenzNickel
Copy link
Contributor

The method will clear the contents of a JsonArray

The method will clear the contents of a JsonArray
@Marcono1234 Marcono1234 mentioned this pull request Aug 22, 2020
@Marcono1234
Copy link
Collaborator

@eamonnmcmanus could you please have a look?

For consistency a JsonObject.clear() method might be useful as well, but that can be done in a separate pull request, if desired.

@eamonnmcmanus
Copy link
Member

I think if we're able to add an asList() method to JsonArray, we shouldn't need other new methods like this?

@Marcono1234
Copy link
Collaborator

Right, though the open question with asList() is still null handling I think.

Maybe clear() is needed often enough to justify having it directly on JsonArray either way? But I am not too sure.

@dhoard
Copy link
Contributor

dhoard commented Nov 9, 2022

I feel that JsonArray/JsonObject clear() would be in common use to reuse an existing object. From an API perspective, it seems like an expected method and a natural match to add(), remove(), etc.

I don't feel that JsonArray/JsonObject should start implementing List/Map methods across the board.

@eamonnmcmanus
Copy link
Member

I think object reuse is poor practice so I don't find that a convincing argument. If people really want to reuse JsonArray instances they can do array.asList().clear(). But making a new JsonArray is generally better. So I'm still unconvinced by JsonArray.clear(), and even more so by JsonObject.clear().

@dhoard
Copy link
Contributor

dhoard commented Nov 13, 2022

I think object reuse is poor practice so I don't find that a convincing argument. If people really want to reuse JsonArray instances they can do array.asList().clear(). But making a new JsonArray is generally better. So I'm still unconvinced by JsonArray.clear(), and even more so by JsonObject.clear().

Fair enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants