Skip to content

Commit 2abd31f

Browse files
committed
fix: properly marshall URL fields to JSON
Marshalling to JSON is used in FFI bindings to pass data around.
1 parent 579bfaa commit 2abd31f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

marshallers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package publiccode
22

33
import (
4+
"encoding/json"
45
"net/url"
56
)
67

@@ -27,6 +28,13 @@ func (u *URL) MarshalYAML() (interface{}, error) {
2728
return u.String(), nil
2829
}
2930

31+
func (u *URL) MarshalJSON() ([]byte, error) {
32+
if u == nil {
33+
return []byte(`null`), nil
34+
}
35+
return json.Marshal(u.String())
36+
}
37+
3038
func (u URL) String() string {
3139
return (*url.URL)(&u).String()
3240
}

0 commit comments

Comments
 (0)