OpenAPITools / OpenAPITools/openapi-generator
[REQ][JAXRS] Support JsonAnyGetter and JsonAnySetter with JAXRS generator to handle unknown properties
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
When using models with inheritance, we can support the following use case with JaxRS:
- Cat inherits from Pet.
- Cat defines additional properties
- My application PetStore handles Pets
- I can send Cats to the application API, with the condition that the Ignore unknown fields in the Mapper is set to true.
- The application is manipulating it as a Pet, and all unknown properties are gathered by the JsonAnySetter.
- When serializing the object again (to store in database or send in the API response), the additional properties are added again via the JsonAnyGetter.
This way, we can seamlessly reuse code for an API defined for the parent, using the child model.
Describe the solution you'd like
I would like to have the possibility to generate, for JaxRS spec models, a map of unknown properties to access the properties that could not be parsed.
private Map<String, Object> unparsedProperties = new HashMap<>();
@JsonAnySetter
public void addUnparsedProperty(String property, Object value){
unparsedProperties.put(property, value);
}
@JsonAnyGetter
public Map<String, Object> getUnparsedProperties(){
return unparsedProperties;
}
This should probably be generated only in the parent in the top of the inheritance chain, so just customizing the model template would not be enough.
For the generator option, would it be better to group that feature in a single option, or let the users generate the @JsonAnySetter and @JsonAnyGetter independently ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files, tests, or entry points. Start by tracing JAXRS spec model generation and inheritance handling, then determine where the unknown-property map and its annotations belong in the top-level generated model. Done means the generator has a defined option and produces the requested behavior for inherited models.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100