Как сделать правильную модель к yaml файлу

У меня есть yaml файл вот такого формата:

channels:
  c_one:
    idS:
      mt: mt_one
      mo: mo_one
    connections:
    - name: name_one
      address: address_one
      port: 19
      use: true
    - name: name_two
      address: address_two
      port: 44
      use: false
   c_two:
     idS:
      mt: mt_two
      mo: mo_two
    connections:
    - name: name_three
      address: address_three
      port: 19
      use: true
    - name: name_four
      address: address_four
      port: 44
      use: false

Для парсинга данного файла я использую jackson:

ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
ChannelsFile cf = yamlMapper.readValue(patch to file, ChannelsFile.class);

Также я сделал класс модели:

@Getter @Setter
public class ChannelsFile {

    private Map<String, Object> channels;
}

Подскажите как добавить остальные поля из yaml файла в данную модель?


Ответы (1 шт):

Автор решения: Alex Rudenko

Может быть следующая реализация:

@Getter @Setter
public class ChannelsFile {

    private Map<String, Channel> channels;

    @Getter @Setter
    public static class Channel {
        private Ids idS;
        private List<Connection> connections;
    }

    @Getter @Setter
    public static class Ids {
        private String mt;
        private String mo;
    }

    @Getter @Setter
    public static class Connection {
        private String name;
        private String address;
        private int port;
        private boolean use;
    }
}
→ Ссылка