Skip to content

<element /> issue? #103

@pj4533

Description

@pj4533

This might be user error, or might be related to #101 not really sure. I am trying to decode:

<?xml version="1.0" encoding="UTF-8"?>
<compendium>
  <foobar>
    <foo>Foo string value</foo>
    <nested>
      <name>Name</name>
      <text>Bar string value</text>
    </nested>
    <nested>
      <name>Name</name>
      <text>Bar string value</text>
      <text />
      <text>Bar string value</text>
    </nested>
  </foobar>
</compendium>

My structs:

           struct NestedObject : Codable {
                var name : String?
                var text : [String]?
            }
            
            struct Foobar : Codable {
                var foo : String?
                var nested : [NestedObject]?
            }
            
            struct Compendium: Codable  {
                var foobars: [Foobar]
                enum CodingKeys: String, CodingKey {
                    case foobars = "foobar"
                }
            }

The empty text in the last nested object fails to decode. I think cause the String inside the array isn't optional, so when not there, the decoder freaks out? Not sure...any help would be appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions