0

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?

  • Can your post your OpenAPI schema definition for this JSON? – Helen Apr 08 '21 at 14:23
  • I just used additional properties to represent the entire JSON. Below is the schema used. *`AppData: title: AppData description: Appdata Request Format type: object properties: appData: type: object additionalProperties: true `* Sorry for this bad formatting @Helen – user3364183 Apr 09 '21 at 15:37

0 Answers0