Adding some more properties to unmarshalling
This commit is contained in:
parent
a516ad03a5
commit
302a70f172
|
@ -1507,6 +1507,10 @@ func (a *Activity) UnmarshalJSON(data []byte) error {
|
|||
a.Parent.UnmarshalJSON(data)
|
||||
a.Actor = JSONGetItem(data, "actor")
|
||||
a.Object = JSONGetItem(data, "object")
|
||||
a.Target = JSONGetItem(data, "target")
|
||||
a.Instrument = JSONGetItem(data, "instrument")
|
||||
a.Origin = JSONGetItem(data, "origin")
|
||||
a.Result = JSONGetItem(data, "result")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
15
link.go
15
link.go
|
@ -22,7 +22,7 @@ type Link struct {
|
|||
// [RFC5988](https://tools.ietf.org/html/rfc5988) "link relation" definitions.
|
||||
// In the [HTML5], any string not containing the "space" U+0020, "tab" (U+0009), "LF" (U+000A),
|
||||
// "FF" (U+000C), "CR" (U+000D) or "," (U+002C) characters can be used as a valid link relation.
|
||||
Rel *Link `jsonld:"rel,omitempty"`
|
||||
Rel IRI `jsonld:"rel,omitempty"`
|
||||
// When used on a Link, identifies the MIME media type of the referenced resource.
|
||||
MediaType MimeType `jsonld:"mediaType,omitempty"`
|
||||
// On a Link, specifies a hint as to the rendering height in device-independent pixels of the linked resource.
|
||||
|
@ -119,11 +119,18 @@ func (l *Link) UnmarshalJSON(data []byte) error {
|
|||
l.ID = JSONGetObjectID(data)
|
||||
l.Type = JSONGetType(data)
|
||||
l.MediaType = JSONGetMimeType(data)
|
||||
l.Preview = JSONGetItem(data, "preview")
|
||||
l.Height = uint(JSONGetInt(data, "height"))
|
||||
l.Width = uint(JSONGetInt(data, "width"))
|
||||
l.Name = JSONGetNaturalLanguageField(data, "name")
|
||||
l.HrefLang = JSONGetLangRefField(data, "hrefLang")
|
||||
u := JSONGetURIItem(data, "href")
|
||||
if u != nil && !u.IsObject() {
|
||||
l.Href = u.GetLink()
|
||||
href := JSONGetURIItem(data, "href")
|
||||
if href != nil && !href.IsObject() {
|
||||
l.Href = href.GetLink()
|
||||
}
|
||||
rel := JSONGetURIItem(data, "rel")
|
||||
if rel != nil && !rel.IsObject() {
|
||||
l.Rel = rel.GetLink()
|
||||
}
|
||||
|
||||
//fmt.Printf("%s\n %#v", data, l)
|
||||
|
|
|
@ -294,7 +294,7 @@ type object struct {
|
|||
AttributedTo Item `jsonld:"attributedTo,omitempty"`
|
||||
// Audience identifies one or more entities that represent the total population of entities
|
||||
// for which the object can considered to be relevant.
|
||||
Audience Item `jsonld:"audience,omitempty"`
|
||||
Audience ItemCollection `jsonld:"audience,omitempty"`
|
||||
// Content or textual representation of the Activity Pub Object encoded as a JSON string.
|
||||
// By default, the value of content is HTML.
|
||||
// The mediaType property can be used in the object to indicate a different content type.
|
||||
|
@ -561,17 +561,24 @@ func (o *Object) UnmarshalJSON(data []byte) error {
|
|||
o.Generator = JSONGetItem(data, "generator")
|
||||
o.AttributedTo = JSONGetItem(data, "attributedTo")
|
||||
o.InReplyTo = JSONGetItem(data, "inReplyTo")
|
||||
o.Attachment = JSONGetItem(data, "attachment")
|
||||
o.Location = JSONGetItem(data, "location")
|
||||
o.Published = JSONGetTime(data, "published")
|
||||
o.StartTime = JSONGetTime(data, "startTime")
|
||||
o.EndTime = JSONGetTime(data, "endTime")
|
||||
o.Duration = JSONGetDuration(data, "duration")
|
||||
o.Icon = JSONGetItem(data, "icon")
|
||||
o.Preview = JSONGetItem(data, "preview")
|
||||
o.Image = JSONGetItem(data, "image")
|
||||
o.Updated = JSONGetTime(data, "updated")
|
||||
to := JSONGetItems(data, "to")
|
||||
if to != nil {
|
||||
o.To = to
|
||||
}
|
||||
audience := JSONGetItems(data, "audience")
|
||||
if audience != nil {
|
||||
o.Audience = audience
|
||||
}
|
||||
bto := JSONGetItems(data, "bto")
|
||||
if bto != nil {
|
||||
o.Bto = bto
|
||||
|
|
|
@ -223,6 +223,14 @@ func JSONGetLangRefField(data []byte, prop string) LangRef {
|
|||
return LangRef(val)
|
||||
}
|
||||
|
||||
func JSONGetIRI(data []byte, prop string) IRI {
|
||||
val, err := jsonparser.GetString(data, prop)
|
||||
if err != nil {
|
||||
return IRI("")
|
||||
}
|
||||
return IRI(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) {
|
||||
|
|
Reference in a new issue