Skip to content

Add clear method to JsonArray - #1667

Closed
LorenzNickel wants to merge 1 commit into
google:masterfrom
LorenzNickel:clear-jsonarray
Closed

Add clear method to JsonArray#1667
LorenzNickel wants to merge 1 commit into
google:masterfrom
LorenzNickel:clear-jsonarray

Conversation

@LorenzNickel

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

@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
Copy Markdown
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
Copy Markdown
Contributor

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

dhoard commented Nov 9, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

dhoard commented Nov 13, 2022

Copy link
Copy Markdown
Contributor

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