Description
Is your feature request related to a problem? Please describe the problem.
The request adapter pattern used by Kiota is pretty slick and it stores request and response parameters as object properties (which I rather like), however some request or response parameter names are valid as JSON or a query param but invalid as an object property name. In particular I am generating Java code and have found that certain OpenAPI specs fail due to odd JSON property names.
For instance, the market v1.2 API here contains a property '@' in one of the JSON responses.
Usually with Jackson or Gson you would use an annotation to handle this type of incompatible mapping. For instance:
// gson
@SerializedName("@")
private String at;
// jackson
@JsonProperty("@")
private String alsoAt;
Is there currently a way to handle property names that don't cleanly map to object properties with Kiota, and if not might I suggest an override registry?
Client library/SDK language
Java
Describe the solution you'd like
Was thinking about this and I don't know if there'd be an easy way to provide meaningful names if you were to automatically replace generated names that don't map to valid object property names appropriately, but it might be easy enough to provide the user a way to supply/override the default behavior with custom mappings as part of a JSON or YML config file, and then just consult this override registry when doing code generation.
That way if a property needs to serialize to a JSON key value that cannot come directly from the object property name due to the name being invalid as an object property, or deserialize from a JSON key value that cannot map to an object property name for the same reason, the user could just supply the replacements.
I think something along the lines of this would work:
{
"path": "", // an optional path to allow for explicit serialization/deserialization at the path level, maybe using JSON dot notation?
"serializeAs": "@", // JSON key to send over the wire for this object property
"deserializeFrom": "@", // JSON key to read from the wire and map to this property
"propertyName": "atSymbol" // The valid Java object property name
}
Additional context
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status