devnote-dev / devnote-dev/xmlt

how to nest multiple classes and deserialize those from xml

Offen
#2 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug good first issue
Vorherrschende Sprache
Crystal
Sterne
8
Forks
0
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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))
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.