October 22, 2024
Chicago 12, Melborne City, USA
java

Parsing hyphenated yaml fields with snakeyaml?


I have a yaml file that looks like this:

resource-path: "src/resource"

The data class is generated by lombok and has methods getResourcePath and setResourcePath. I’ve checked these by printing out the methods on the class to be sure.

When I try to populate that data class I get this error:

Unable to find property resource-path on class.

And the code I’m using to parse the yaml and populate the data class is just this:

Yaml yaml = new Yaml();
yaml.loadAs(new FileInputStream(dataFile), Data.class);

It was my understanding that snakeyaml will derive a camelcase field name from a hyphenated field. So in my case it should be getResourcePath and setResourcePath which are both on the data class. I’ve been reading the docs, but do not see anything that would be helpful. Is there a setting or something else I’m missing?

I’m using snakeyaml 2.2.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video