Changes
4 changed files (+69/-11)
-
-
@@ -664,17 +664,32 @@ func loadLink(data []byte, l *Link) error {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")) h := JSONGetInt(data, "height") if h != 0 { l.Height = uint(h) } w := JSONGetInt(data, "width") if w != 0 { l.Width = uint(w) } l.Name = JSONGetNaturalLanguageField(data, "name") l.HrefLang = JSONGetLangRefField(data, "hrefLang") hrefLang := JSONGetLangRefField(data, "hrefLang") if len(hrefLang) > 0 { l.HrefLang = hrefLang } href := JSONGetURIItem(data, "href") if href != nil && !href.IsObject() { l.Href = href.GetLink() if href != nil { ll := href.GetLink() if len(ll) > 0 { l.Href = ll } } rel := JSONGetURIItem(data, "rel") if rel != nil && !rel.IsObject() { l.Rel = rel.GetLink() if rel != nil { rr := rel.GetLink() if len(rr) > 0 { l.Rel = rr } } return nil }
-
-
-
@@ -308,3 +308,37 @@ func writeQuestionValue(b *[]byte, q Question) (notEmpty bool) {notEmpty = writeBoolProp(b, "closed", q.Closed) || notEmpty return notEmpty } func writeLinkValue(b *[]byte, l Link) (notEmpty bool) { if v, err := l.ID.MarshalJSON(); err == nil && len(v) > 0 { notEmpty = writeProp(b, "id", v) || notEmpty } if v, err := l.Type.MarshalJSON(); err == nil && len(v) > 0 { notEmpty = writeProp(b, "type", v) || notEmpty } if v, err := l.MediaType.MarshalJSON(); err == nil && len(v) > 0 { notEmpty = writeProp(b, "mediaType", v) || notEmpty } if len(l.Name) > 0 { notEmpty = writeNaturalLanguageProp(b, "name", l.Name) || notEmpty } if v, err := l.Rel.MarshalJSON(); err == nil && len(v) > 0 { notEmpty = writeProp(b, "rel", v) || notEmpty } if l.Height > 0 { notEmpty = writeIntProp(b, "height", int64(l.Height)) } if l.Width > 0 { notEmpty = writeIntProp(b, "width", int64(l.Width)) } if l.Preview != nil { notEmpty = writeItemProp(b, "rel", l.Preview) || notEmpty } if v, err := l.Href.MarshalJSON(); err == nil && len(v) > 0 { notEmpty = writeProp(b, "href", v) || notEmpty } if len(l.HrefLang) > 0 { notEmpty = writeStringProp(b, "hrefLang", string(l.HrefLang)) || notEmpty } return notEmpty }
-
-
-
@@ -94,6 +94,18 @@ func (l Link) GetType() ActivityVocabularyType {return l.Type } // MarshalJSON func (l Link) MarshalJSON() ([]byte, error) { b := make([]byte, 0) write(&b, '{') if writeLinkValue(&b, l) { write(&b, '}') return b, nil } return nil, nil } // UnmarshalJSON func (l *Link) UnmarshalJSON(data []byte) error { return loadLink(data, l)
-
-
-
@@ -262,12 +262,9 @@ func (o *Object) UnmarshalJSON(data []byte) error {// MarshalJSON func (o Object) MarshalJSON() ([]byte, error) { b := make([]byte, 0) notEmpty := false write(&b, '{') notEmpty = writeObjectValue(&b, o) if notEmpty { if writeObjectValue(&b, o) { write(&b, '}') return b, nil }
-