I have a REST API which accepts application/json in RequestBody. The keys in the json is not predefined. So I have used additionalProperties in swagger to define this JSON. Also, this json may hold JSONArray also.
The problem is, when additionalProperties is used, it is internally taken as Map<String, Object> in the generated java code. This map is deserialized to JSON by using Gson internally. During this conversion, the below json
{
"BooleanField": "true",
"ArrayField": [
"SDK ADD",
"SDK ADD 2"
],
"StringField": "SDK",
"IntField": "1"
}
is converted as
{
"BooleanField": "true",
"ArrayField": {
"myArrayList": [
"SDK ADD",
"SDK ADD 2"
]
},
"StringField": "SDK",
"IntField": "1"
}
The json array is put in myArrayList key. This causes input validation failure for this request. Is there any better way to solve this?