You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Franz Wong <fr...@gmail.com> on 2020/05/23 02:04:56 UTC
[configurations] Custom data type conversion
Hello, I am trying to convert for custom data type.
Data type:
@Data
class Character {
private String name;
private String type;
}
YAML:
characters:
- name: Luke Skywalker
type: Jedi
- name: Jar Jar Binks
- name: Darth Vader
type: Sith
Code:
List<Character> characters = config.getList(Character.class, "characters");
Actually I found that it is not possible to do something like that easily,
then I change the YAML to this.
characters:
- Luke Skywalker,Jedi
- Jar Jar Binks,
- Darth Vader,Sith
When I override DefaultConversionHandler's convertValue method, I
found that PropertyConverter is a final class with default scope. It means
I can't reuse this class.
I am just thinking should we make that class a public class or even we
should have something like Map<Class, Converter>, so that we don't need to
extend DefaultConversionHandler and just add a new Converter to it. How do
you think?
By the way, the "Subscribe" mailing list links on
http://commons.apache.org/proper/commons-configuration/mailing-lists.html
are broken.
Thanks.
Franz