Support for additional properties
See original GitHub issueIt is sometimes the case that I want to parse an object with a few concrete properties and a bunch of additional properties.
OpenAPI 3’s Responses Object is an example for this. It has the fixed default
default plus additional fields for various http statuses.
so this could look like:
{
"default": {...},
"200": {...},
"400": {...},
"404": {...}
}
And it would be great to be able to parse this into something like:
@Serializable
data class Responses(val default: Response, statuses: Map<String, Response>)
Jackson has the @JsonAnySetter
annotation which can be used to implement this.
OpenAPI/JSON Schema support specifying object schemas that have both properties
and additionalProperties
.
Currently I think the only solution would be a hand-written KSerializer for Responses.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Schema in a response allows additional properties
The schema you have defined allows additional properties, either intentionally or unintentionally. In JSON, by default, any object can also accept additional ...
Read more >Additional Properties - JSON Schema Editor
The value of "patternProperties" MUST be an object. Each property name of this object SHOULD be a valid regular expression, according to the...
Read more >[BUG] Version 4 no longer supports additionalProperties ...
additionalProperties - Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object and not a standard JSON...
Read more >AdditionalProperties
The AdditionalProperties element identifies additional properties for use in GetItem, UpdateItem, CreateItem, FindItem, or FindFolder ...
Read more >Usage
See 'openapi-generator-cli help <command>' for more information on a ... command for a go client, use the --additional-properties option.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I guess “require” is a strong word here. Technically it is obviously not required since there is at least two alternative approaches.
However it would be great to have a dedicated feature for that, especially since this requires duplicating field names into the transformation which can easily go out of sync with the model.
An annotation
@AdditionalFields
or@UnknownFields
on aMap<*, *>
field that then automatically collects all fields that are not consumed by other fields would be what comes to my mind.Yes, it still requires one, but given that
JsonTransformingSerializer
is much easier to implement, I’m not sure that this feature needs special support