generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
Description
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 classwith
@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.
Line 108 in a6a3ec9
private String basePath = "will-be-overwritten";
mehdijouan