cloud-sdk-java
cloud-sdk-java copied to clipboard
Feature request: Enable convenient API access to customize OpenAPI (de)serialization options.
Scenario:
- My target OpenAPI endpoint gives an error upon receiving
nullvalues - total garbage, I know.
Use Case:
- Currently this is the code, that I need to invoke to stop null serialization on my generated OpenAPI code:
Destination destination;
ApiClient apiClient = new ApiClient(createRestTemplate(destination));
apiClient.setBasePath(destination.getUri().toString()); // argsl... (see side-issue)
new DefaultApi(apiClient); // my service class
with
@SuppressWarnings("UnstableApiUsage")
private static RestTemplate createRestTemplate(Destination destination) {
var objectMapper = new Jackson2ObjectMapperBuilder()
.modules(new JavaTimeModule())
.visibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
.visibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.NONE)
.serializationInclusion(JsonInclude.Include.NON_NULL) // THIS STOPS `null` serialization
.build();
var httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
httpRequestFactory.setHttpClient(ApacheHttpClient5Accessor.getHttpClient(destination));
var result = new RestTemplate();
result.getMessageConverters()
.stream()
.filter(MappingJackson2HttpMessageConverter.class::isInstance)
.map(MappingJackson2HttpMessageConverter.class::cast)
.forEach(converter -> converter.setObjectMapper(objectMapper));
result.setRequestFactory(new BufferingClientHttpRequestFactory(httpRequestFactory));
return result;
}
Feature request:
- Please provide a convenient way to customize (de)serialization options on
ApiClientor the generated Service class respectively.- It looks like the easiest option would be to expose some existing private methods on
ApiClientas protected, such that I can overload them upon class instantiation.
- It looks like the easiest option would be to expose some existing private methods on
Side issue:
- When instantiating the
ApiClientmyself thebasePathwill not be overwritten by default. Independent whether I use theDestination-based orRestTemplate-based constructor. https://github.com/SAP/cloud-sdk-java/blob/a6a3ec9e61119ed0d23a5761dd2bfa88c8ddde27/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apiclient/ApiClient.java#L108