| 1193 | } |
| 1194 | |
| 1195 | func (doc *Document) MarshalJSON() (data []byte, err error) { |
| 1196 | // The calling code in ImportDoc will marshal the document since it takes a body with _sync inline. |
| 1197 | // Make sure that _sync._attachments is present in the document body since _globalSync._attachments_meta |
| 1198 | // can not be seen in an inline body. |
| 1199 | doc.SyncData.AttachmentsPre4dot0 = doc.Attachments() |
| 1200 | defer func() { doc.SyncData.AttachmentsPre4dot0 = nil }() |
| 1201 | if doc._rawBody != nil { |
| 1202 | data, err = base.InjectJSONProperties(doc._rawBody, base.KVPair{ |
| 1203 | Key: base.SyncPropertyName, |
| 1204 | Val: doc.SyncData, |
| 1205 | }) |
| 1206 | } else { |
| 1207 | body := doc._body |
| 1208 | if body == nil { |
| 1209 | body = Body{} |
| 1210 | } |
| 1211 | body[base.SyncPropertyName] = &doc.SyncData |
| 1212 | data, err = base.JSONMarshal(body) |
| 1213 | delete(body, base.SyncPropertyName) |
| 1214 | if err != nil { |
| 1215 | err = pkgerrors.WithStack(base.RedactErrorf("Failed to MarshalJSON() doc with id: %s. Error: %v", base.UD(doc.ID), err)) |
| 1216 | } |
| 1217 | } |
| 1218 | return data, err |
| 1219 | } |
| 1220 | |
| 1221 | // UnmarshalWithXattrs unmarshals the provided raw document and xattr bytes when present. The provided DocumentUnmarshalLevel |
| 1222 | // (unmarshalLevel) specifies how much of the provided document/xattr needs to be initially unmarshalled. If |