Support custom name for enum value

Issue #311 resolved
Julien Herr created an issue

I'd like to read/write YAML where the YAML value will be "true" or "false", and Java part is an enum.

Sadly, it is not possible to have enum value named "true" or "false", and SnakeYAML won't find it if I use another name (for example "TRUE" or "FALSE").

Comments (10)

  1. Andrey Somov

    What is the YAML document and what is the Java code ? By the way, you can turn off the implicit conversion true/false -> boolean.

  2. Julien Herr reporter

    In fact, I tried to replace an old String enum by a "new" Java 5 one. The source is here: https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/xml/XmlSuite.java

    This class is used in XML and YAML conversion (https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/internal/Yaml.java).

    The problem is the parallel attribute where possible values are: tests, methods, classes, instances, none, true and false.

    I started to use uppercase name for enum values but SnakeYAML didn't find attributes. And I cannot use lowercase due to true and false values.

    I think that having a way to specify the enum name we want could be a nice solution. Or maybe SnakeYAML provides a way to use custom converter but I didn't find something like that.

    I can have 2 different classes too but I'd prefer to have only one description class for many export if possible.

  3. Andrey Somov

    I must admit that after your clarification it became even less clear. Can you please show an example of a YAML file you want to use ?

  4. Julien Herr reporter

    It doesn't solve the problem because the expected value in xml/yaml is in lower case ("true", "false", ...).

  5. Andrey Somov

    I have improved the example, now this YAML can be parsed (lower case, no quotes):

    {boolField: true, enumField: true, name: '10'}

  6. Log in to comment