Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

582
Vistas
Convert Swagger Java Object into JSON/YAML

I need to read, modify and re-generate a JSON/YAML swagger file documentation. I have deserialized a JSON file with Swagger Parser and I have a Swagger Java Object with the original JSON data mapped correctly.

Now, I need to modify the Swagger Java object, and generate a JSON or YAML file with the done modifications.

Is there a way to do that?

Summary:

File fileJSON = FileUtils.toFile(getClass().getResource("example-api-rest.json"));

Swagger swagger = new SwaggerParser().read(fileJSON.getPath()); //Got it!
...
swagger.editWhatever
...
//Here I need to generate the JSON or YAML again

Thanks.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

To generate JSON:

import io.swagger.util.Json;

String jsonOutput = Json.pretty(swagger);

To generate YAML:

import io.swagger.util.Yaml;

String yamlOutput = Yaml.pretty().writeValueAsString(swagger);

The io.swagger.util package is part of Swagger Core, which is one of the dependencies of Swagger Parser.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda