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

207
Vistas
How to parse part of .yaml file to object in SnakeYAML?

I have a yaml file, for example:

# this is the part I don't care about
config:
  key-1: val-1
other-config:
  lang: en
  year: 1906
# below is the only part I care about
interesting-setup:
  port: 1234
  validation: false
  parts:
    - on-start: backup
      on-stop: say-goodbye

Also I have a POJO class that is suitable for the interesting-setup part

public class InterestingSetup {
    int port;
    boolean validation;
    List<Map<String, String>> parts;
}

I want to load just the interesting-setup part (similarly as @ConfigurationProperties("interesting-setup") in Spring)

Currently I'm doing it like this:

Map<String, Object> yamlConfig = yaml.load(yamlFile);            # loading the whole file to Map with Object values
Object interestingObject = yamlConfig.get("interesting-setup");  # loading 'interesting-setup' part as an object
Map<String, Object> interestingMap = (Map<String, Object>);      # Casting object to Map<String, Object>
String yamlDumped = yaml.dump(interestingMap);                   # Serialization to String
InterestingSetup finalObject = yaml.load(yamlDumped);            # Getting final object from String

The crucial part is when I have an Object (Map<String, Object>) and want to cast it to my final class. To do that - I need to serialize it to String, so the process looks like this:

File -> Map<String, Object> -> Object -> Map<String, Object> -> String -> FinalClass and I'd like to avoid deserialization and again serialization of the same data.

So can I somehow use Yaml to map the Map<String, Object> to another class? I cannot see this in an API?

over 4 years ago · Santiago Trujillo
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