Skip to content

Nested Cbor Tags are not unmarshalled properly #13

@dignifiedquire

Description

@dignifiedquire

Something strange is going on when trying to unmarshal cbor tags that are nested. Object in question can be found here: https://github.com/ipfs/go-ipld-cbor/blob/refmt/node_test.go#L124-L133

obj := map[string]interface{}{
    "foo":   "bar",
    "hello": c1,
    "baz": []interface{}{
      c1,
      c2,
    },
    "cats": map[string]interface{}{
      "qux": c3,
    },
  }

The byte code looks fine

a36362617a82d82a5823001220aed1fe98cda4ba5a1681a19aa768f73b9d707c5621c7effdf2938e242080505ed82a58230012205773487d221545d26fd0f57fdb3a7d986bc479a850d7b0d762e8c7f4772790a06463617473a163717578d82a5823001220434be0538b88f385bdb9d62de34e296a0908c857a876aec09e1f52673596d89763666f6f63626172

Diagnostic view from cbor.me

{"baz": [42(h'001220AED1FE98CDA4BA5A1681A19AA768F73B9D707C5621C7EFFDF2938E242080505E'), 42(h'0012205773487D221545D26FD0F57FDB3A7D986BC479A850D7B0D762E8C7F4772790A0')], "cats": {"qux": 42(h'001220434BE0538B88F385BDB9D62DE34E296A0908C857A876AEC09E1F52673596D897')}, "foo": "bar"}

But after unmarshalling this is what I get as json representation:

original

{"baz": [{"/":"Qma75NN8GaM99ioqsNUF9Ho816SonoGsVrvSnqz9uL4LPF"},{"/":"QmUE28rcN99es8ntD4T3sBScfyrADkF3q8qzM1gEW82oMh"}],"cats":{"qux":{"/":"QmSsM8Xm1g5WtfwkBvnttZafpDhaW6jkXeSFccECUnx7hg"}},"foo":"bar","hello":{"/":"Qma75NN8GaM99ioqsNUF9Ho816SonoGsVrvSnqz9uL4LPF"}} 

after roundtrip

{"baz":[{},{}],"cats":{"qux":{}},"foo":"bar","hello":{}}

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