-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Kotlin support for index access operators #1844
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I am not sure whether adding more methods with different names but the same behavior as existing methods is really worth it, especially since the main target of this project seems to be Java. Have a look at https://github.com/square/moshi which is designed for Kotlin.
I have added some review comments, but it might not be worth it considering them because this project does not seem to be actively maintained anymore, see #1821.
Note that I am not a maintainer of this project.
I don't know if it is still maintained, but still making this PR. Everything is resolved now. |
Reviving this conversation. 🙂 operator fun JsonObject.set(property: String, value: JsonElement) = add(property, value)
operator fun JsonObject.set(property: String, value: String) = addProperty(property, value)
operator fun JsonObject.set(property: String, value: Number) = addProperty(property, value)
operator fun JsonObject.set(property: String, value: Boolean) = addProperty(property, value)
operator fun JsonObject.set(property: String, value: Char) = addProperty(property, value) It would be good if there were a standard artifact to house extension functions like these. I don't think the main Gson artifact ( |
In Kotlin you can define your own operators. You can use the ::set Method to add a object. See https://kotlinlang.org/docs/reference/keyword-reference.html for more.
I added the set method in JsonObject. It is a simple alias to add or addProperty.
Also I need the current String position in JsonReader. E.g I have a command as a string and the next argument is a JsonObject. I just want to know how many chars were read from the input string to determinate the next argument. Currently this looks like this: