@@ -205,34 +205,28 @@ AV._getValue = function(object, prop) {
205205 * is set, then none of the AV Objects that are serialized can be dirty.
206206 * @private
207207 */
208- AV . _encode = function ( value , seenObjects , disallowObjects ) {
208+ AV . _encode = function ( value , seenObjects , disallowObjects , full ) {
209209 if ( value instanceof AV . Object ) {
210210 if ( disallowObjects ) {
211211 throw new Error ( "AV.Objects not allowed here" ) ;
212212 }
213213 if ( ! seenObjects || _ . include ( seenObjects , value ) || ! value . _hasData ) {
214214 return value . _toPointer ( ) ;
215215 }
216- if ( ! value . dirty ( ) ) {
217- seenObjects = seenObjects . concat ( value ) ;
218- return AV . _encode ( value . _toFullJSON ( seenObjects ) ,
219- seenObjects ,
220- disallowObjects ) ;
221- }
222- throw new Error ( "Tried to save an object with a pointer to a new, unsaved object." ) ;
216+ return value . _toFullJSON ( seenObjects . concat ( value ) , full ) ;
223217 }
224218 if ( value instanceof AV . ACL ) {
225219 return value . toJSON ( ) ;
226220 }
227221 if ( _ . isDate ( value ) ) {
228- return { "__type" : "Date" , "iso" : value . toJSON ( ) } ;
222+ return full ? { "__type" : "Date" , "iso" : value . toJSON ( ) } : value . toJSON ( ) ;
229223 }
230224 if ( value instanceof AV . GeoPoint ) {
231225 return value . toJSON ( ) ;
232226 }
233227 if ( _ . isArray ( value ) ) {
234228 return _ . map ( value , function ( x ) {
235- return AV . _encode ( x , seenObjects , disallowObjects ) ;
229+ return AV . _encode ( x , seenObjects , disallowObjects , full ) ;
236230 } ) ;
237231 }
238232 if ( _ . isRegExp ( value ) ) {
@@ -248,10 +242,10 @@ AV._encode = function(value, seenObjects, disallowObjects) {
248242 if ( ! value . url ( ) && ! value . id ) {
249243 throw new Error ( "Tried to save an object containing an unsaved file." ) ;
250244 }
251- return value . _toFullJSON ( ) ;
245+ return value . _toFullJSON ( seenObjects , full ) ;
252246 }
253247 if ( _ . isObject ( value ) ) {
254- return _ . mapObject ( value , ( v , k ) => AV . _encode ( v , seenObjects , disallowObjects ) ) ;
248+ return _ . mapObject ( value , ( v , k ) => AV . _encode ( v , seenObjects , disallowObjects , full ) ) ;
255249 }
256250 return value ;
257251} ;
@@ -337,6 +331,14 @@ AV._decode = function(value, key) {
337331 return _ . mapObject ( value , AV . _decode ) ;
338332} ;
339333
334+ /**
335+ * The inverse function of {@link AV.Object#toFullJSON}.
336+ * @since 2.0.0
337+ * @param {Object }
338+ * return {AV.Object|AV.File|any}
339+ */
340+ AV . parseJSON = AV . _decode ;
341+
340342AV . _encodeObjectOrArray = function ( value ) {
341343 var encodeAVObject = function ( object ) {
342344 if ( object && object . _toFullJSON ) {
0 commit comments