devnote-dev / devnote-dev/xmlt

how to nest multiple classes and deserialize those from xml

Abierto
#2 0 comentarios 0 reacciones 0 asignados Ver en GitHub
bug good first issue
Lenguaje dominante
Crystal
Estrellas
8
Forks
0
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.