Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
e9c901db
Commit
e9c901db
authored
Nov 08, 2010
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
json: don't indirect before testing for custom unmarshaler
Fixes #1260. R=gri CC=golang-dev
https://golang.org/cl/2994041
parent
9f19392f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
src/pkg/json/decode.go
src/pkg/json/decode.go
+3
-1
src/pkg/json/decode_test.go
src/pkg/json/decode_test.go
+22
-0
No files found.
src/pkg/json/decode.go
View file @
e9c901db
...
...
@@ -128,7 +128,9 @@ func (d *decodeState) unmarshal(v interface{}) (err os.Error) {
}
d
.
scan
.
reset
()
d
.
value
(
pv
.
Elem
())
// We decode rv not pv.Elem because the Unmarshaler interface
// test must be applied at the top level of the value.
d
.
value
(
rv
)
return
d
.
savedError
}
...
...
src/pkg/json/decode_test.go
View file @
e9c901db
...
...
@@ -23,6 +23,24 @@ type tx struct {
var
txType
=
reflect
.
Typeof
((
*
tx
)(
nil
))
.
(
*
reflect
.
PtrType
)
.
Elem
()
.
(
*
reflect
.
StructType
)
// A type that can unmarshal itself.
type
unmarshaler
struct
{
T
bool
}
func
(
u
*
unmarshaler
)
UnmarshalJSON
(
b
[]
byte
)
os
.
Error
{
*
u
=
unmarshaler
{
true
}
// All we need to see that UnmarshalJson is called.
return
nil
}
var
(
um0
,
um1
unmarshaler
// target2 of unmarshaling
ump
=
&
um1
umtrue
=
unmarshaler
{
true
}
)
type
unmarshalTest
struct
{
in
string
ptr
interface
{}
...
...
@@ -56,6 +74,10 @@ var unmarshalTests = []unmarshalTest{
{
pallValueCompact
,
new
(
All
),
pallValue
,
nil
},
{
pallValueIndent
,
new
(
*
All
),
&
pallValue
,
nil
},
{
pallValueCompact
,
new
(
*
All
),
&
pallValue
,
nil
},
// unmarshal interface test
{
`{"T":false}`
,
&
um0
,
umtrue
,
nil
},
// use "false" so test will fail if custom unmarshaler is not called
{
`{"T":false}`
,
&
ump
,
&
umtrue
,
nil
},
}
func
TestMarshal
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment