Deserializing key "on" fails with Exception

Issue #522 closed
ArloK created an issue

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)

  1. ArloK reporter

    Thanks for the quick reply, Andrey!

    Am I understanding this correctly that YAML supports boolean values as keys? What a weird spec…

  2. Alexander Maslov

    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…

  3. Log in to comment