Skip to content

Commit 5d42ef1

Browse files
authored
Rename Unmarshal func (#17)
1 parent cbfecf2 commit 5d42ef1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

jsn.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ func (f F) MarshalJSON() ([]byte, error) {
3838

3939
// Unmarshal only 1 JSON entity from the input.
4040
// Disallows unknown fields if the argument is a struct.
41-
func Unmarshal(r io.Reader, v any) error {
41+
func Unmarshal(b []byte, v any) error {
42+
return UnmarshalFrom(bytes.NewReader(b), v)
43+
}
44+
45+
// UnmarshalFrom reader only 1 JSON entity from the input.
46+
// Disallows unknown fields if the argument is a struct.
47+
func UnmarshalFrom(r io.Reader, v any) error {
4248
d := json.NewDecoder(r)
4349
d.DisallowUnknownFields()
4450

jsn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestUnmarshal(t *testing.T) {
4747

4848
for _, tc := range testCases {
4949
var val any
50-
err := UnmarshalBytes([]byte(tc.input), &val)
50+
err := Unmarshal([]byte(tc.input), &val)
5151
if err != nil {
5252
if tc.errStr == "" {
5353
t.Fatal(err)

0 commit comments

Comments
 (0)