Deserialization issue w/ JavaBeans

Issue #389 invalid
Ismail Aydemir created an issue

SnakeYAML 1.8 Java Version: 1.8

Create a JavaBean class (ClassMustBe) that has a List<String> property called parameterSets

Call Yaml().loadAs(yamlString,ClassMustBe.class) with the yamlString being the following:

!test.bean.property parameterSets: !!java.lang.Object [!!java.io.FileOutputStream [file_created]]

Note that no exception is thrown, and the file is created. If you remove the parent java.lang.Object node, a argument type mismatch gets thrown, but the file still gets created.

I would expect that before creating a new instance of class that a check would be performed to make sure that the type is an appropriate one.

ConstructSequence.construct: if (foundConstructor) { try { return c.newInstance(argumentList.toArray()); } catch (Exception e) { throw new YAMLException(e); } } } }

Comments (4)

  1. Ismail Aydemir reporter

    I've attached the test I wrote earlier when looking into this. Running the Test file will create a new DifferentClass object (which will print it's constructor args), as well as a new file titled file_created. test/test2.yaml files contain the payloads used in the loadAs method.

  2. Andrey Somov

    The fact that you call a file a 'Test' does not make it a test.

    If you write the an appropriate test where we can see what should succeed and what (and how) should fail - you make our life much easier.

    I do not get this statement: "I would expect that before creating a new instance of class that a check would be performed to make sure that the type is an appropriate one." What you mean by 'appropriate' ?

  3. Log in to comment