Skip to content
Advertisement

Parse list of beans with snakeyaml

Is it possible to parse with snakeyaml the following content and obtain a List<Radio> (where Radio is the appropriate java bean) ?

JavaScript

new Yaml().load(...); returns a List<HashMap>, but I’d like to get a List<Radio> instead.

Advertisement

Answer

The only way I know is to use a top object to handle the collection.

Yaml file :

JavaScript

I just added “—” , new document and an attribute stations.

Then :

JavaScript

The class RadioStation :

JavaScript

And to read the YAML file :

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement