File: json.go

package info (click to toggle)
golang-github-blang-semver 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, experimental, sid
  • size: 176 kB
  • sloc: makefile: 3
file content (23 lines) | stat: -rw-r--r-- 467 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package semver

import (
	"encoding/json"
)

// MarshalJSON implements the encoding/json.Marshaler interface.
func (v Version) MarshalJSON() ([]byte, error) {
	return json.Marshal(v.String())
}

// UnmarshalJSON implements the encoding/json.Unmarshaler interface.
func (v *Version) UnmarshalJSON(data []byte) (err error) {
	var versionString string

	if err = json.Unmarshal(data, &versionString); err != nil {
		return
	}

	*v, err = Parse(versionString)

	return
}