encoding/json: Decoding gives errPhase when unmarshaling a non-string literal into a TextUnmarshaler #9650
Comments
Note that this doesn't happen when json value is quoted as expected by TextUnmarshaler.
|
@alytvynov This bug report is for non-string literals. It is true that it passes the correct error for string literals. I just noticed that this happens even when the TextUnmarshaler doesn't return an error. Updating the description now. |
@cespare sure, just pointing that out as a possible hint for debugging. |
@rsc: Two questions about your fix:
|
updated
When decoding a non-string literal into an
encoding.TextUnmarshaler
(such asnet.IP
),json.Unmarshal
returnserrPhase
("JSON decoder out of sync - data changing underfoot?").Reading the code, it seems like it's supposed to return a type error when this happens
(source). But the
errPhase
ends up taking precedence and obscuring this message.I'm not sure why
UnmarshalText
should only work for string literals, though.Example play here.
Code:
The text was updated successfully, but these errors were encountered: