2012-01-17 1 views
3

でjava.util.Setをロードするためにどのように私は、次のYAMLシーケンスをロードしようエラーは、snakeYamlがjava.util.Setの代わりにjava.util.Listにシーケンスをロードするためです。はsnakeYAML

snakeYAMLにjava.util.Setのシーケンスを強制的にロードする方法ですか?

org.yaml.snakeyaml.error.YAMLException: org.yaml.snakeyaml.error.YAMLException: Cannot set property='children' with value='[Person [firstName=Bill, secondName=Lumbergh], Person [firstName=Jane, secondName=Lumbergh]]' (class java.util.ArrayList) in Person [firstName=Paul, secondName=Lumbergh] 
at org.yaml.snakeyaml.extensions.compactnotation.CompactConstructor$ConstructCompactObject.construct(CompactConstructor.java:163) 
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183) 
at org.yaml.snakeyaml.constructor.BaseConstructor.constructSequenceStep2(BaseConstructor.java:277) 
at org.yaml.snakeyaml.constructor.BaseConstructor.constructSequence(BaseConstructor.java:248) 
at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlSeq.construct(SafeConstructor.java:440) 
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183) 
at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:142) 
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:128) 
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480) 
at org.yaml.snakeyaml.Yaml.load(Yaml.java:411) 
at com.pearson.fixy.Fixy.loadEntities(Fixy.java:105) 
at com.pearson.fixy.Fixy.load(Fixy.java:126) 
at com.dvidea.TestFixy.test(TestFixy.java:24) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 
+0

あなたは 'java.util.Set'を意味していますか? – millimoose

+0

はい私はjava.util.Setを持つBeanを持っています – mmounirou

+0

あなたはあなたが試している関連するコードを投稿できますか? – maerics

答えて

2

YAML specificationによると、設定された構文は、次のいずれかを見る必要があるかもしれ :

- Person(paul): 
    firstName: Paul 
    lastName: Lumbergh 
    children : !!set ? Person(bill) ? Person(jane) – 
+0

これは実際に動作しますか?リンクは10年前に更新された作業草案です。 – pimlottc

0

SnakeYAMLに、SetではなくListを使用させます。セットはYAMLで別の表現をしています:http://yaml.org/type/set.html

YAMLドキュメントを変更したり、リストの代わりにセットを使用するようにSnakeYAMLに指示したりできます。あなたはin tests

関連する問題