Added generic UnmarshalJSON for activitystreams package
This commit is contained in:
parent
323d792a70
commit
4a4c72b09e
|
@ -282,6 +282,12 @@ func getAPLangRefField(data []byte, prop string) LangRef {
|
|||
return LangRef(val)
|
||||
}
|
||||
|
||||
// UnmarshalJSON tries to detect the type of the object in the json data and then outputs a matching
|
||||
// ActivityStreams object, if possible
|
||||
func UnmarshalJSON(data []byte) (Item, error) {
|
||||
return unmarshalToAPObject(data), nil
|
||||
}
|
||||
|
||||
/*
|
||||
func unmarshal(data []byte, a interface{}) (interface{}, error) {
|
||||
ta := make(mockObj, 0)
|
||||
|
|
14
activitystreams/unmarshalling_test.go
Normal file
14
activitystreams/unmarshalling_test.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package activitystreams
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestUnmarshalJSON(t *testing.T) {
|
||||
dataEmpty := []byte("{}")
|
||||
i, err := UnmarshalJSON(dataEmpty)
|
||||
if err != nil {
|
||||
t.Errorf("invalid unmarshalling %s", err)
|
||||
}
|
||||
|
||||
o := *i.(*Object)
|
||||
validateEmptyObject(o, t)
|
||||
}
|
Reference in a new issue