Skip to content

Add JsonObject field reading syntax sugar#3019

Open
huicunjun wants to merge 9 commits intoKotlin:devfrom
huicunjun:dev
Open

Add JsonObject field reading syntax sugar#3019
huicunjun wants to merge 9 commits intoKotlin:devfrom
huicunjun:dev

Conversation

@huicunjun
Copy link
Copy Markdown

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

@pdvrieze Can you review it

@pdvrieze
Copy link
Copy Markdown
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