- edited description
Deserializing key "on" fails with Exception
I am trying to deserialize GitHub Actions Workflow syntax files. These contain a key “on”.
name: CodeQL Analysis
on:
push:
branches: main
Sadly this cannot be mapped onto a Java object. I tried isolating the issue and could break it down to his
on: "CodeQL Analysis"
public class Workflow {
private String on;
...
}
The exception is
Exception in thread "main" Can't construct a java object for tag:yaml.org,2002:io.github.arlol.chori
to.chores.githubactions.Workflow; exception=class java.lang.Boolean cannot be cast to class java.lan
g.String (java.lang.Boolean and java.lang.String are in module java.base of loader 'bootstrap')
in 'reader', line 1, column 1:
Hopefully this helps to reproduce the error. If I can provide more info, please let me know
My guess would be that there is some confusion in regards to the special boolean values “off” and “on” that is mixing things up.
Comments (11)
-
reporter -
SnakeYAML supports YAML 1.1 where on has boolean meaning
You can
- implement your own Resolver (you can find examples in tests)
- use Engine
-
reporter Thanks for the quick reply, Andrey!
Am I understanding this correctly that YAML supports boolean values as keys? What a weird spec…
-
SnakeYAML supports ANY value as key (boolean, map, list etc)
-
- changed status to invalid
-
reporter Thanks for the clarification. Will look into Engine
-
I think this is an interesting case and maybe need to be fixed.
Even if specs says that “on”, “off”…. are considered as Boolean values, when we create JavaBean, I think, it is worth to consider keys as Strings and ignore any kind of type resolution. Maybe it is not that simple, but still…I wouldn’t do anything for Map, but for JavaBeans…
-
- changed status to open
-
-
assigned issue to
- marked as enhancement
- marked as minor
-
assigned issue to
-
- changed status to resolved
force keyNode to be String for JavaBeans
fixes issue
#522- it is possible now use properties with names equal to the values accepted as boolean in YAML 1.1→ <<cset 046878427009>>
-
- changed status to closed
it will be delivered in 1.31
- Log in to comment