Closed amreladawy closed 4 years ago
Are you using raml defined types ? Have you tried with additional properties ?
Yes, I am using raml defined types. I just would like to have way to annotate the generated model in order to ignore any unknown properties in the server response json. I forgot to say that I am using it for REST client.
Ok, you are generating the model and using it in a rest client. Are you generating the jackson 2 annotations ?
Here is my plugin config details.
<plugin>
<groupId>org.raml.jaxrs</groupId>
<artifactId>raml-to-jaxrs-maven-plugin</artifactId>
<version>${raml-jaxrs-version}</version>
<dependencies>
<dependency>
<groupId>org.raml.jaxrs</groupId>
<artifactId>jaxrs-code-generator</artifactId>
<version>${raml-jaxrs-version}</version>
</dependency>
</dependencies>
<configuration>
<ramlFile>${basedir}/src/main/resources/</ramlFile>
<includes>
<include>candidate-api/candidate.raml</include>
<include>order-api/order-api-proxy.raml</include>
</includes>
<resourcePackage>com.resources</resourcePackage>
<modelPackage>com.model</modelPackage>
<supportPackage>com.support</supportPackage>
<generateTypesWith>
</generateTypesWith>
<jsonMapperConfiguration>
<!-- <CustomAnnotator>@JsonIgnoreProperties(ignoreUnknown = true)</CustomAnnotator>-->
</jsonMapperConfiguration>
</configuration>
</plugin>
You should activate the plugins. Here, I've activated jackson2, jsr303 and equalsAndHashCode.
<modelPackage>example.model</modelPackage>
<resourcePackage>example.types</resourcePackage>
<supportPackage>example.support</supportPackage>
<generateTypesWith>
<value>jackson2</value>
<value>jsr303</value>
<value>equalsAndHashCode</value>
</generateTypesWith>
I have done this, but what should I except?
I can close this as I disabled the feature DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
on the ObjectMapper instead of annotating models with the JsonIgnoreProperties
If the code generated has the JsonAnyGetter and JsonAnySetter annotation, that should pick up any extra properties in there.
So jackson should be happy.
Those additionalProperties
properties were added to the model. I am going to close this, as I can ignore additional unknown properties by customising the mapper
val target = ClientBuilder.newClient().register(
ContextResolver {
ObjectMapper()
.enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature())
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.registerModule(Jdk8Module()).registerModule(ParameterNamesModule()).registerModule(GuavaModule())
}
).target(url)
If there are unknown json properties, deserialisation fails.