Skip to content

Add JsonObject field reading syntax sugar #3019

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

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

huicunjun
Copy link

Add Enhanced JsonObject deserialization and field reading syntax sugar

public fun JsonObject.getJsonArray(key: String): JsonArray? = this[key]?.jsonArray
public fun JsonObject.getJsonPrimitive(key: String): JsonPrimitive? = this[key]?.jsonPrimitive
public fun JsonObject.getJsonNull(key: String): JsonNull? = this[key]?.jsonNull
public fun JsonObject.getIntOrNull(key: String): Int? = this[key]?.jsonPrimitive?.intOrNull
Copy link
Contributor

Choose a reason for hiding this comment

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

This (and similar) functions should include a check that it is not a string isString should return false

Copy link
Author

Choose a reason for hiding this comment

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

This (and similar) functions should include a check that it is not a string isString should return false

If I don't check isString , it seems to have no consequences, I guess it should be the converted type?
image

@huicunjun huicunjun changed the title Add Enhanced JsonObject deserialization and field reading syntax sugar Add JsonObject field reading syntax sugar Jun 17, 2025
@huicunjun
Copy link
Author

@pdvrieze Can you review it

@pdvrieze
Copy link
Contributor

@huicunjun It looks good to me (not an official maintainer so can't do anything beyond that)

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

Successfully merging this pull request may close these issues.

2 participants