Skip to content

Commit 1a9a0e4

Browse files
authored
Use encoding TextMarshaler & TextUnmarshaler instead json equivalents (#95)
1 parent 82485a6 commit 1a9a0e4

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

version.go

+9-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package version
22

33
import (
44
"bytes"
5-
"encoding/json"
65
"fmt"
76
"reflect"
87
"regexp"
@@ -390,25 +389,19 @@ func (v *Version) Original() string {
390389
return v.original
391390
}
392391

393-
// UnmarshalJSON implements JSON.Unmarshaler interface.
394-
func (v *Version) UnmarshalJSON(b []byte) error {
395-
var s string
396-
if err := json.Unmarshal(b, &s); err != nil {
397-
return err
398-
}
399-
temp, err := NewVersion(s)
392+
// UnmarshalText implements encoding.TextUnmarshaler interface.
393+
func (v *Version) UnmarshalText(b []byte) error {
394+
temp, err := NewVersion(string(b))
400395
if err != nil {
401396
return err
402397
}
403-
v.metadata = temp.metadata
404-
v.pre = temp.pre
405-
v.segments = temp.segments
406-
v.si = temp.si
407-
v.original = temp.original
398+
399+
*v = *temp
400+
408401
return nil
409402
}
410403

411-
// MarshalJSON implements JSON.Marshaler interface.
412-
func (v Version) MarshalJSON() ([]byte, error) {
413-
return json.Marshal(v.String())
404+
// MarshalText implements encoding.TextMarshaler interface.
405+
func (v *Version) MarshalText() ([]byte, error) {
406+
return []byte(v.String()), nil
414407
}

0 commit comments

Comments
 (0)