EDIT FOR CLARITY: We're using JsonSchema2POJO in our gradle.config file to generate java classes on build. These classes are continuously deleted and created when we clean and build, so adjusting the classes rather than the gradle file or the schema isn't maintainable. In the JsonSchema2POJO gradle script we've set includeAdditionalProperties = true, and in all schemas we've set "additionalProperties": true. However, when additional properties are included in an object to be validated against the schema, Jackson throws an UnrecognizedPropertyException. The exception is not thrown if we explicitly declare an "additionalProperties": {} object in the json, but I'm looking for a way to get any additional properties to simply be added to the additionalProperties object in the java class without explicitly declaring the "additionalProperties": {} object in the json message, preferably from the gradle or schema files.
I'm sending a json request to a newly created service. The way I've been instructed to code it, several different schemas are rolled into one: all schemas have to have "someString", and depending on the value of "someString" the request gets parsed into one of several objects - one may require "someOtherString" while another may not use "someOtherString" and instead use "someInteger". Once the request comes in and the value of "someString" is parsed, it can be translated into another object based on that value.
The schema for the service looks like this:
"mySchema.json"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"someString": {
"type": "string",
"minLength": 1
},
"required": [
"someString"
],
"javaName": "mySchemaObject",
"additionalProperties": true
}
}
However, when I try so send the below request, I catch the exception further below:
JSON Request:
{
"someString": "someStringValue",
"someObject": {
"someOtherString": someOtherStringValue
}
}
Exception:
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "someObject" (Class: com.my.package.someClass)
The same thing occurs with the below request:
{
"someString": "someStringValue",
"someOtherString": someOtherStringValue
}
Exception:
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "someOtherString" (Class: com.my.package.someClass)
If I adjust the request to the following, it gets through the filter:
{
"someString": "someStringValue,
"additionalProperties": {
"someOtherString": "someOtherStringValue"
}
}
In all the examples I see of schemas involving additionalProperties, you don't actually need to include an "additionalProperties" object... is this unique to jackson? Is there a way to set any properties not listed in the schema as additionalProperties by default?