9

In my spring boot application, I am using snakeyaml to parse a YAML file. I get the following error though when using the library:

java.lang.NoSuchMethodError: org.yaml.snakeyaml.nodes.ScalarNode.getStyle()Ljava/lang/Character;

I am using the following maven dependency:

<dependency>
  <groupId>org.yaml</groupId>
  <artifactId>snakeyaml</artifactId>
  <version>1.21</version>
</dependency>

Does anyone have a hint for resolving this error?

Edit:

The error seems to occur when parsing spring's application.yml:

server:
  port: 8084
user2035039
  • 961
  • 3
  • 16
  • 30

2 Answers2

17

You need to update to SnakeYml 1.23, they fixed the incompatible API change introduced in 1.20.

<dependency>
  <groupId>org.yaml</groupId>
  <artifactId>snakeyaml</artifactId>
  <version>1.23</version>
</dependency>
Leonard Brünings
  • 12,408
  • 1
  • 46
  • 66
6

That is due to this change:

Refactor ScalarNode - use enum ScalarStyle instead of Character

You can either roll back to SnakeYaml 1.19, which is the last release before this change, or wait for Spring Boot to support SnakeYaml 1.20+.

flyx
  • 35,506
  • 7
  • 89
  • 126
  • version 1.19 causes "illegal reflective access" on jdk 9 – cybersoft Jun 21 '18 at 20:52
  • @cybersoft See [this issue](https://bitbucket.org/asomov/snakeyaml/issues/393/warning-an-illegal-reflective-access). Fixed in 1.20, bummer. – flyx Jun 22 '18 at 09:05
  • yes, I know, but I use Spring Boot 2 and [it does not work yet](https://github.com/spring-projects/spring-boot/issues/13191) with snakeyaml 1.20+ – cybersoft Jun 23 '18 at 10:00
  • Yeah, that's the point. I just wanted to add context for other people having this problem. I don't know of any solution, apart from using an older jdk. – flyx Jun 23 '18 at 10:19
  • Thanks @flyx. I changed mine to the latest version of snakeyml, it solved the issue. – Chi Jul 13 '20 at 03:53