devnote-dev / devnote-dev/xmlt

how to nest multiple classes and deserialize those from xml

オープン
#2 コメント 0 件 リアクション 0 件 担当者 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 を短くまとめたダイジェスト。