- edited description
Global tag is not allowed: tag:yaml.org,2002:com.example.Snake
Issue #1063
invalid
When using snakeyaml 2.0, dumping and loading the dumped message runs into an exception:
Global tag is not allowed: tag:yaml.org,2002:com.example.Snake
in 'string', line 1, column 1:
!!com.example.Snake { ...
^
at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:304)
at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:209)
at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:131)
at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:157)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:178)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:493)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:422)
Test case:
@Test
public void message_customJavaClass() {
// given
Snake message = new Snake();
message.setMessage("snakeyaml test");
String serializedMessage = new Yaml().dump(message);
// when
Snake parsedMessage = new Yaml().load(serializedMessage);
// then
assertEquals("snakeyaml test", parsedMessage.getMessage());
}
Snake class:
public class Snake {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
As far as I can see this dumping and re-loading should work.
Thanks for you help.
Comments (7)
-
reporter -
reporter - edited description
-
- changed status to open
-
- marked as minor
-
assigned issue to
-
This is the major backwards incompatibility with SnakeYAML 1
Please check this mega false positive
You should explicitly configure SnakeYAML to allow global tags
LoaderOptions.
setTagInspector
(your own rule) -
- changed status to invalid
as designed in version 2.0
-
reporter Thanks for the info Andrey, I will have a look at it.
- Log in to comment