-
Notifications
You must be signed in to change notification settings - Fork 14
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
Representing object
s with arbitrary keys and values
#35
Comments
additionalProperties: true
)object
with arbitrary keys and values
object
with arbitrary keys and valuesobject
s with arbitrary keys and values
For posterity and FYI, here's how I worked around this: Schema: {
"$id": "https://groundplatform.org/loi-document.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"foo": {
"type": "object",
"x-local-type": "map"
}
}
} config.json: {
"customClasses": {
"extension": {
"x-local-type": {
"map": "kotlin.collections.Map"
}
}
}
} The generated code: import kotlin.collections.Map
data class LoiDocument(
val foo: Map? = null,
) Unfortunately, generics aren't working in the class mapping since they cause the following invalid import to be generated: import kotlin.collections.Map<String, Any> I worked around this by defining a typealias: Map.kt: typealias Map = kotlin.collections.Map<String, Any> And then referring to that in the mapping in config.json instead of Full solution in google/ground-android#2205 |
Hi @gino-m , I often find myself having to respond to requests and suggestions from users by saying that their proposal sounds great, but it would be competing for my time with other equally worthy developments. In this case, however, I can tell you that a solution for your issue has been under active development for a few weeks now, and I'm hopeful of having a working version within a week to ten days (yes, I'm aware of Hofstadter's Law). Thank you for confirming the demand for this functionality; I'll report back here when I have a version for you to test. In the meantime, the use of custom classes and a |
Hi @pwall567, thanks for your prompt, thoughtful reply. It's encouraging to know that issues and FRs are being addressed. We'd be happy to test out a fix once it's available. Keep up the great work! |
OK, as expected, it took longer than I expected, but version 0.100 has now been uploaded to Maven Central. This version includes support for I hope this meets your needs, and I would welcome any feedback you may be able to give me. |
@pwall567 This is great news! And timely, since we're just getting back to applying JSON Schema in groundplatform.org. Thank you for the fix and the update! |
@os-micmec FYI |
Defining
"type": "object"
in JSON Schema always causes an open class to be generated, even when no properties are defined. How do we represent a plain Map, where property keys and values are determined at runtime?Here's what I have now:
Example schema:
Note:
"additionalProperties": true
is the default in JSON Schema, including it here for clarity.The generated code:
The text was updated successfully, but these errors were encountered: