Added generic UnmarshalJSON for activitystreams package

This commit is contained in:
Marius Orcsik 2018-11-22 13:35:20 +01:00
parent 323d792a70
commit 4a4c72b09e
No known key found for this signature in database
GPG key ID: 889CE8E4FB2D877A
2 changed files with 20 additions and 0 deletions

View file

@ -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)

View 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)
}