Fix quotes being kept for string type aliases in UnmarshalJSON methods
This commit is contained in:
parent
12f481a243
commit
6b75ad6d68
|
@ -4,9 +4,8 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/buger/jsonparser"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ObjectID designates an unique global identifier.
|
// ObjectID designates an unique global identifier.
|
||||||
|
@ -93,12 +92,13 @@ type (
|
||||||
ActivityObject
|
ActivityObject
|
||||||
GetID() ObjectID
|
GetID() ObjectID
|
||||||
GetType() ActivityVocabularyType
|
GetType() ActivityVocabularyType
|
||||||
|
//UnmarshalJSON([]byte) error
|
||||||
}
|
}
|
||||||
// ObjectsArr is a named type for matching an ObjectOrLink slice type to Collection interface
|
// ObjectsArr is a named type for matching an ObjectOrLink slice type to Collection interface
|
||||||
ObjectsArr []ObjectOrLink
|
ObjectsArr []ObjectOrLink
|
||||||
// LinkOrURI is an interface that GetID and GetLink structs implement, and at the same time
|
// LinkOrURI is an interface that GetID and GetLink structs implement, and at the same time
|
||||||
// they are kept disjointed
|
// they are kept disjointed
|
||||||
LinkOrURI interface{
|
LinkOrURI interface {
|
||||||
GetLink() URI
|
GetLink() URI
|
||||||
}
|
}
|
||||||
// ImageOrLink is an interface that Image and GetLink structs implement
|
// ImageOrLink is an interface that Image and GetLink structs implement
|
||||||
|
@ -360,18 +360,21 @@ func recipientsDeduplication(recArgs ...*ObjectsArr) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ObjectID) MarshalJSON(data []byte) error {
|
// UnmarshalJSON
|
||||||
*i = ObjectID(data)
|
func (i *ObjectID) UnmarshalJSON(data []byte) error {
|
||||||
|
*i = ObjectID(strings.Trim(string(data), "\""))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ContentType) MarshalJSON(data []byte) error {
|
// UnmarshalJSON
|
||||||
*c = ContentType(data)
|
func (c *ContentType) UnmarshalJSON(data []byte) error {
|
||||||
|
*c = ContentType(strings.Trim(string(data), "\""))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Object) MarshalJSON(data []byte) error {
|
//func (o *Object) UnmarshalJSON(data []byte) error {
|
||||||
val, _, _, _ := jsonparser.Get(data, "ID")
|
// //_o, err := unmarshalJSONFromType(data, ObjectType)
|
||||||
o.ID.MarshalJSON(val)
|
//
|
||||||
return nil
|
// //*o = _o.(Object)
|
||||||
}
|
// return nil
|
||||||
|
//}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// IRI is a Internationalized Resource Identifiers (IRIs) RFC3987
|
// IRI is a Internationalized Resource Identifiers (IRIs) RFC3987
|
||||||
IRI URI
|
IRI URI
|
||||||
|
@ -27,3 +31,15 @@ func (u URI) GetLink() URI {
|
||||||
func (i IRI) GetLink() URI {
|
func (i IRI) GetLink() URI {
|
||||||
return URI(i)
|
return URI(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON
|
||||||
|
func (u *URI) UnmarshalJSON(s []byte) error {
|
||||||
|
*u = URI(strings.Trim(string(s), "\""))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON
|
||||||
|
func (i *IRI) UnmarshalJSON(s []byte) error {
|
||||||
|
*i = IRI(strings.Trim(string(s), "\""))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Reference in a new issue