0

Have the list of complex objects in YML format:

Messages: 
  error1: 
    code: 0988
    text: "error message1"
  error2: 
    code: 0988
    text: "error message2"

I need to map this structure to java class:

public class MessageProvider {
    private Message error1;
    private Message error2;
    //getters, setters

    public static class Message{
        private String text;
        private String code;
        //getters, setters
    }
}

Is it possible to map it by using spring boot capabilities ? If yes, I will be thankful for example.

Speise
  • 789
  • 1
  • 12
  • 28
  • The example is shown in a related (tab on the right) question: https://stackoverflow.com/a/40153935/3080094 A little bit more searching might help next time. – vanOekel Jul 16 '17 at 08:20
  • in the link you provided is list of elements but it is not about what i'm asking. – Speise Jul 16 '17 at 13:48

1 Answers1

1

According to the this Yaml Tutorial this is how to suppose to deserialize a yaml file:

YamlReader reader = new YamlReader(new FileReader("your-yaml.yml"));
Object object = reader.read();
System.out.println(object);
MessageProvider map = (MessageProvider)object;
System.out.println(map.get("error1"));
Gal Dreiman
  • 3,969
  • 2
  • 21
  • 40