'POJO to YAML using Jackson and lombok

I am trying to get following kind of yaml using pojo jackson and lombok

 paths:
  /courses:
    summary: Operations about Courses
    description: Contains the list operation on courses
    get:
      tags:
        - course
      summary: Get all the courses
      description: Returns the list of all courses
      operationId: getCourses
      parameters: 
        - name: sortBy
          in: query
          description: The sort order
          schema:
            type: string
            enum:
              - asc
              - desc
            default: asc
      responses:
        '200':
          description: Succesfully returned all course details
          content:
            application/json:
              schema:
                type: array
                items:
                   courseId: 1
                   courseName: Computer Science
                   courseDuration: 4
                   courseType: Engineering
        '4XX':
          description: Bad Request
        '5XX':
          description: Internal Server Error
        default:
          description: Success

my code:

 ArrayList<Object> statuscodes = new ArrayList<Object>();
        {
            HashMap<String, String> status = new HashMap<String, String>();
            {
                status.put("200", "OK");
                status.put("4XX", "Bad Request");
                status.put("5XX", "Internal Server Error");
            }
            statuscodes.add(status);
        }
        Parameters parameters = Parameters.builder().name("sortBy").in("query").description("The sort order").required("false").schema("string type").build();
        Get get = Get.builder().tags("course").summary("Get all the courses").description("Returns the list of all courses").operationId("getCourses").parameters(parameters).build();
        Status status = Status.builder().statuscodes(statuscodes).build();
        Paths paths = Paths.builder().summary("Operations about Courses").description("Contains the list operation on courses").get(get).build();
        YamlTO yamlTO = YamlTO.builder().paths(paths).build();

        try {

 
            ObjectMapper object = new ObjectMapper(new YAMLFactory());

            object.writeValue(new File("target/file.yaml"), yamlTO);

        } catch (final Exception e) {
            e.printStackTrace();
        }

    }

I have declared all required variables in respective classes and used lombok build, getter, setter, argsconstructor there.

but the YAMl structure is too complex to fetch required data in similar format. Any suggestion on my code? or any other way?

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source