Fixed source property unmarshalling
This commit is contained in:
parent
88e637fb3f
commit
a955ef13ec
|
@ -27,12 +27,10 @@ type Object struct {
|
||||||
func GetAPSource(data []byte) Source {
|
func GetAPSource(data []byte) Source {
|
||||||
s := Source{}
|
s := Source{}
|
||||||
|
|
||||||
contBytes, _, _, err := jsonparser.Get(data, "source", "content")
|
if contBytes, _, _, err := jsonparser.Get(data, "source", "content"); err == nil {
|
||||||
if err == nil {
|
|
||||||
s.Content.UnmarshalJSON(contBytes)
|
s.Content.UnmarshalJSON(contBytes)
|
||||||
}
|
}
|
||||||
mimeBytes, _, _, err := jsonparser.Get(data, "source", "mimeType")
|
if mimeBytes, _, _, err := jsonparser.Get(data, "source", "mediaType"); err == nil {
|
||||||
if err == nil {
|
|
||||||
s.MediaType.UnmarshalJSON(mimeBytes)
|
s.MediaType.UnmarshalJSON(mimeBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func validateEmptyObject(o Object, t *testing.T) {
|
func validateEmptyObject(o Object, t *testing.T) {
|
||||||
if o.ID != "" {
|
if o.ID != "" {
|
||||||
|
@ -60,3 +62,16 @@ func TestSource_UnmarshalJSON(t *testing.T) {
|
||||||
s.UnmarshalJSON(dataEmpty)
|
s.UnmarshalJSON(dataEmpty)
|
||||||
validateEmptySource(s, t)
|
validateEmptySource(s, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetAPSource(t *testing.T) {
|
||||||
|
data := []byte(`{"source": {"content": "test", "mediaType": "text/plain" }}`)
|
||||||
|
|
||||||
|
a := GetAPSource(data)
|
||||||
|
|
||||||
|
if a.Content.First() != "test" {
|
||||||
|
t.Errorf("Content didn't match test value. Received %q, expecting %q", a.Content, "test")
|
||||||
|
}
|
||||||
|
if a.MediaType != "text/plain" {
|
||||||
|
t.Errorf("Content didn't match test value. Received %q, expecting %q", a.MediaType, "text/plain")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -227,6 +227,8 @@ func (l *LangRef) UnmarshalText(data []byte) error {
|
||||||
func (n *NaturalLanguageValue) UnmarshalJSON(data []byte) error {
|
func (n *NaturalLanguageValue) UnmarshalJSON(data []byte) error {
|
||||||
val, typ, _, err := jsonparser.Get(data)
|
val, typ, _, err := jsonparser.Get(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// try our luck if data contains an unquoted string
|
||||||
|
n.Append(NilLangRef, string(data))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
switch typ {
|
switch typ {
|
||||||
|
@ -418,9 +420,9 @@ type Relationship struct {
|
||||||
type Tombstone struct {
|
type Tombstone struct {
|
||||||
Parent
|
Parent
|
||||||
// FormerType On a Tombstone object, the formerType property identifies the type of the object that was deleted.
|
// FormerType On a Tombstone object, the formerType property identifies the type of the object that was deleted.
|
||||||
FormerType ActivityVocabularyType `jsonld:"formerType,omitempty"`
|
FormerType ActivityVocabularyType `jsonld:"formerType,omitempty"`
|
||||||
// Deleted On a Tombstone object, the deleted property is a timestamp for when the object was deleted.
|
// Deleted On a Tombstone object, the deleted property is a timestamp for when the object was deleted.
|
||||||
Deleted time.Time `jsonld:"deleted,omitempty"`
|
Deleted time.Time `jsonld:"deleted,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidGenericType validates the type against the valid generic object types
|
// ValidGenericType validates the type against the valid generic object types
|
||||||
|
|
Reference in a new issue