devnote-dev / devnote-dev/xmlt

how to nest multiple classes and deserialize those from xml

未关闭
#2 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug good first issue
主要语言
Crystal
星标
8
派生
0
PR 合并指标
30 天内没有已合并 PR

描述

how to make the following work

```crystal
require "xmlt"

XML_FRAGMET = <<-XML

2

test


test2

XML

class Element
include XMLT::Serializable

property name : String
end

class Repository
include XMLT::Serializable

property version : String

@[XMLT::Field(new_root: "element")]
property elements : Array(Element)
end

module Txmltest
repo = Repository.from_xml XML_FRAGMET, root: "repository"
p! repo.version
if elements = repo.elements
elements.each do |elm|
p! elm
end
end
end
```

I get the following error

```
~/P/C/txmltest (main) [1]> shards run
Dependencies are satisfied
Building: txmltest
Error target txmltest failed to compile:
Showing last frame. Use --error-trace for full trace.

In lib/xmlt/src/objects.cr:18:5

18 | new node, root: root
^--
Error: no overload matches 'Array(Element).new' with types XML::Node, root: String

Overloads are:
- Array(T).new(size : Int, value : T)
- Array(T).new(initial_capacity : Int)
- Array(T).new()
- Array(T).new(size : Int, & : (Int32 -> T))
```

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。