'How can I read an array/object of a hocon file from java

I am trying to change my project configuration files from YAML to HOCON. Everything went fine except when I ran into a file that uses array/object.

This is the YAML file:

interactions:
  example1:
    questions:
      - 'How do i get money?'
      - 'Does anyone know how to get money?'
      - 'I need money'
    answers:
      - '{player} you have to sell in the store'
      - '{player} sell items'
    options:
      response_chance: 30
      required_real_players: 5
      wait_per_letter: 0.3
  example2:
    questions:
      - 'I want to buy a block in the store'
      - 'I want to go to the store'
      - 'where do I get blocks'
    answers:
      - '{player} type /shop'
      - '{player} to buy items type /shop'
    options:
      response_chance: 30
      required_real_players: 5
      wait_per_letter: 0.3

This is how I read this file in java:

Object[] fields = main.getConfig().getConfigurationSection("interactions").getKeys(false).toArray();
                for (Object key : fields){
                    for(String question : main.getConfig().getStringList("interactions."+key+".questions")) {
                        List<String> answers = main.getConfig().getStringList("interactions."+key+".answers");

I have tried to adapt it to HOCON and this is how it turned out:

interactions {
    example1=[
        {
            questions=[
                "How do i get money?"
                "Does anyone know how to get money?"
                "I need money"
            ]
            answers=[
                "{player} you have to sell in the store"
                "{player} sell items"
            ]
            options= {
                response chance = 30
                requiered real players = 0
                wait per letter = 0.3
            }
        }
    ]
    example2=[
        {
            questions=[
                "I want to buy a block in the store"
                "I want to go to the store"
                "where do I get blocks"
            ]
            answers=[
                "{player} type /shop"
                "{player} to buy items type /shop"
            ]
            options= {
                response chance = 30
                requiered real players = 0
                wait per letter = 0.3
            }
        }
    ]
}

Now how can I read this file using a java class?



Sources

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

Source: Stack Overflow

Solution Source