Skip to content

Bool deserialization errors for internally-tagged enum variants #43

Description

@aramperes

I have a patch with a unit test demonstrating this issue (the test internal_variant_bool fails at deserialization): aramperes@0056f45

thread 'internal_variant_bool' panicked at 'NBT deserialization.: Serde("invalid type: integer `1`, expected a boolean")', src/libcore/result.rs:999:5

Context: Internally-tagged enum representation is a serde feature to define the struct used based on a field inside of said struct. In the patch, I am serializing a deserializing the following "variants" (represented as JSON here):

// internal_variant_string
{
  "data": {
    "variant": "String",
    "data": "test"
  }
}

// internal_variant_bool
{
  "data": {
    "variant": "Bool",
    "data": true
  }
}

There seems to be an incompatibility between this serde feature and hematite_nbt's bool deserialization mechanism. The error message shows that it is happening at the serde-level, which makes me think the deserialize_bool in nbt::de is not executed in this particular test case.

An easy work-around is to use u8 instead of bool for the BoolVariant struct.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions