Scenario:
- My target OpenAPI endpoint gives an error upon receiving
null values - 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
ApiClient or the generated Service class respectively.
- It looks like the easiest option would be to expose some existing private methods on
ApiClient as protected, such that I can overload them upon class instantiation.
Side issue:
- When instantiating the
ApiClient myself the basePath will not be overwritten by default. Independent whether I use the Destination-based or RestTemplate-based constructor.
|
private String basePath = "will-be-overwritten"; |
Scenario:
nullvalues - total garbage, I know.Use Case:
with
Feature request:
ApiClientor the generated Service class respectively.ApiClientas protected, such that I can overload them upon class instantiation.Side issue:
ApiClientmyself thebasePathwill not be overwritten by default. Independent whether I use theDestination-based orRestTemplate-based constructor.cloud-sdk-java/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apiclient/ApiClient.java
Line 108 in a6a3ec9