Skip to content

encoding/json: struct field implementing Unmarshaler #2170

@gopherbot

Description

@gopherbot

by akunokuroneko:

What steps will reproduce the problem?
1. Create a custom type that implements Unmarshaller against it's immediate (not
pointer) value.
2. Use type as an exported immediate value in a struct.
3. json.Decode() and watch the unmarshal fail.

What is the expected output?
The Unmarshaller method to be invoked.

What do you see instead?
"json: cannot unmarshal string into Go value of type ..."

(in this case, string is the literal type being used in the JSON stream to fudge the
custom type)

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Linux amd64

Which revision are you using?  (hg identify)
r59

Please provide any additional information below.
Patch attached.

Attachments:

  1. json-unmarshal-immediate.diff (799 bytes)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions