JYAML:序列化/反序列化嵌套/内部类

发布于 2024-08-15 12:42:54 字数 563 浏览 3 评论 0原文

首先祝大家圣诞快乐!

现在回答我的问题: 假设我有一个 Outer 类和一些内部类 Inner。作为 Outer 中的字段,我有一个 List,然后我想将其转储到 YAML 文件。我这样做:

Outer o = new Outer();
o.innerList = new ArrayList<Inner>();
o.innerList.add(new o.Inner());
...
Yaml.dump(o, new File("test.yml");

这给了我一个例外: Exception in thread "main" org.ho.yaml.exception.ObjectCreationException: Error close line 0: Can't create object of type class game.Outer$Inner using默认构造函数。

我尝试提供自定义构造函数并将访问级别更改为公共,但没有帮助。有什么想法吗?

First of all, Merry Christmas to everyone!

Now to my question:
Let's say I have the class Outer with some inner class Inner. As a field in Outer, I have a List<Inner>, which i then want to dump to a YAML file. I do this like so:

Outer o = new Outer();
o.innerList = new ArrayList<Inner>();
o.innerList.add(new o.Inner());
...
Yaml.dump(o, new File("test.yml");

This gives me the exception: Exception in thread "main" org.ho.yaml.exception.ObjectCreationException: Error near line 0: Can't create object of type class game.Outer$Inner using default constructor.

I tried providing a custom constructor and changing the access level to public, to no help. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

混浊又暗下来 2024-08-22 12:42:54

SnakeYAML 有很多带有内部类的示例。
YAML 文档 (test.yml) 是什么样的?
Inner 是静态内部类吗?

SnakeYAML has a lot of examples with inner classes.
How does the YAML document (test.yml) look like ?
Is Inner a static inner class ?

白色秋天 2024-08-22 12:42:54

首先是检查 YAML 是否支持内部类序列化。

First thing is check that YAML supports the Inner class serialization.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文