-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use this with Spring Boot #18
Comments
In Spring Boot, just add @Bean
public JsonNullableModule jsonNullableModule {
return new JsonNullableModule();
} Spring boot will load it into its ObjectMapper (so you must not override it) during autoconf. |
And you don't need to explicitly load JacksonConfiguration if it's visible by the component scan. |
Thanks for the quick reply @cbornet , I still see the same message. Here's another part:
|
Can you provide a sample app reproducing the problem ? |
I'll try but I can't promis, schedules are tight. It should be enough to have a simple model with a openApiGenerate {
generatorName = "java"
library = "resttemplate"
verbose = true
validateSpec = true
skipValidateSpec = false
inputSpec = "$rootDir/src/main/resources/schema_oas3.yaml"
outputDir = "$rootDir/../api"
configOptions = [
dateLibrary: "java8",
openApiNullable: "true"
]
apiPackage = 'a.b.openapi'
modelPackage = 'a.b.openapi.model'
invokerPackage = 'a.b.openapi.client'
groupId = 'a.b'
id = 'some_api'
version = '0.1'
} Kick off a new spring boot 2.3 app, nothing fancy, just @Autowired
private DefaultApi api;
public static void main(final String[] args) {
LOG.info("STARTING THE APPLICATION");
SpringApplication.run(MyApplication.class, args);
LOG.info("APPLICATION FINISHED");
}
@Override
public void run(final String... args) throws Exception {
// api.getApiClient().setBasePath("http://localhost:8000");
SomeResponse200 response200 = api.getList(...);
} |
@black-snow or whoever else might be interested in this... I've had the same issue. I don't think I understand the whole picture, but I this may be of help. Spring uses a bunch of different In the stack trace I got that you also posted above, there should be a In my case, the problem was happening at
Your solution might differ slightly, but I think the problem might be roughly the same. |
I had to do something similar: @Configuration
public class JsonConfig {
@Bean
public JsonNullableModule jsonNullableModule(ObjectMapper objectMapper) {
var module=new JsonNullableModule();
objectMapper.registerModule(module);
return module;
}
@Bean
public RestTemplate template(ObjectMapper objectMapper){
var converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(objectMapper);
return new RestTemplateBuilder()
...
.additionalMessageConverters(converter)
.build();
}
@Bean
public ApiClient getApiClient(RestTemplate restTemplate){
var client=new ApiClient(restTemplate);
client.setBasePath(...);
return client;
}
} |
@GregoireW Thanks for the comment, it resolved my issue |
I generated the client code from my OAS 3.0.3 spec for
java
,resttemplate
andjava8
asdateLibrary
.I had to explicitly set
openApiNullable
to true in the gradle plugin - otherwise I had to manually add this dependency to the generated build.gradle.My spring boot
2.3.x
app has a configuration:that I explicitly import:
But I just keep hitting
The text was updated successfully, but these errors were encountered: