3

I'm using a swagger yaml file to define my API and generate Java code out of it. With this structure:

SomeStructure:
  type: object
  properties:
    field1:      
      type: string
      required: true
    field2:
      type: string
      required: true
    field3:
      type: string
      additionalProperties: {}

Now, once API code generation is done, I would like the 3rd field to flatten any specified JSON structure into a Java String.

For instance, for an input like this:

{
    "field1":"value1",
    "field2":"value2",
    "field3":{
        "subvalue1":"subvalue1",
        "subvalue2":"subvalue2"
  }
}

I want it to get mapped to a String containing:

{"subvalue1":"subvalue1","subvalue2":"subvalue2"}

I tried to use the freeform indicator '{}', but obviously, it's not working. Is it possible, and how do I do this?

JS Bournival
  • 113
  • 2
  • 7
  • Question Is not much clear. Can you please provide more inputs> – Dhanasekaran Don Dec 05 '22 at 12:54
  • 1
    can you please elaborate more so that we can understand the use case properly and provide our inputs – Shubam Virdi Dec 06 '22 at 12:18
  • It can't be done during generation. It seems like the only way is to use additionalProperties which generates a Map field, and then after generation when you use the field3, convert that to a JSON String with ObjectMapper.writeValueAsString(map). – Emmanuel Dec 07 '22 at 19:06

0 Answers0