diff --git a/integration/test/ParseObjectTest.js b/integration/test/ParseObjectTest.js index ef3aed26a..07877eddf 100644 --- a/integration/test/ParseObjectTest.js +++ b/integration/test/ParseObjectTest.js @@ -2056,6 +2056,44 @@ describe('Parse Object', () => { expect(obj.get('string')).toBeInstanceOf(String); }); + it('returns correct field values', async () => { + const values = [ + { field: 'string', value: 'string' }, + { field: 'number', value: 1 }, + { field: 'boolean', value: true }, + { field: 'array', value: [0, 1, 2] }, + { field: 'array', value: [1, 2, 3] }, + { field: 'array', value: [{ '0': 'a' }, 2, 3] }, + { field: 'object', value: { key: 'value' } }, + { field: 'object', value: { key1: 'value1', key2: 'value2' } }, + { field: 'object', value: { key1: 1, key2: 2 } }, + { field: 'object', value: { '1x1': 1 } }, + { field: 'object', value: { '1x1': 1, '2': 2 } }, + { field: 'object', value: { '0': 0 } }, + { field: 'object', value: { '1': 1 } }, + { field: 'object', value: { '0': { '0': 'a', '1': 'b' } } }, + { field: 'date', value: new Date() }, + { + field: 'file', + value: Parse.File.fromJSON({ + __type: 'File', + name: 'name', + url: 'http://localhost:1337/parse/files/integration/name', + }), + }, + { field: 'geoPoint', value: new Parse.GeoPoint(40, -30) }, + { field: 'bytes', value: { __type: 'Bytes', base64: 'ZnJveW8=' } }, + ]; + for (const value of values) { + const object = new TestObject(); + object.set(value.field, value.value); + await object.save(); + const query = new Parse.Query(TestObject); + const objectAgain = await query.get(object.id); + expect(objectAgain.get(value.field)).toEqual(value.value); + } + }); + describe('allowCustomObjectId', () => { it('can save without setting an objectId', async () => { await reconfigureServer({ allowCustomObjectId: true }); diff --git a/src/ObjectStateMutations.ts b/src/ObjectStateMutations.ts index 3292fb88e..cd3616278 100644 --- a/src/ObjectStateMutations.ts +++ b/src/ObjectStateMutations.ts @@ -184,18 +184,7 @@ export function commitServerChanges( ) { const ParseObject = CoreManager.getParseObject(); for (const attr in changes) { - let val = changes[attr]; - // Check for JSON array { '0': { something }, '1': { something } } - if ( - val && - typeof val === 'object' && - !Array.isArray(val) && - Object.keys(val).length > 0 && - Object.keys(val).some(k => !isNaN(parseInt(k))) && - !['sentPerUTCOffset', 'failedPerUTCOffset'].includes(attr) - ) { - val = Object.values(val); - } + const val = changes[attr]; nestedSet(serverData, attr, val); if ( val && diff --git a/src/__tests__/ObjectStateMutations-test.js b/src/__tests__/ObjectStateMutations-test.js index b224ef326..99dbe5134 100644 --- a/src/__tests__/ObjectStateMutations-test.js +++ b/src/__tests__/ObjectStateMutations-test.js @@ -319,8 +319,9 @@ describe('ObjectStateMutations', () => { ObjectStateMutations.commitServerChanges(serverData, objectCache, { items: { '0': { count: 20 }, '1': { count: 5 } }, }); - expect(serverData).toEqual({ items: [{ count: 20 }, { count: 5 }] }); - expect(objectCache).toEqual({ items: '[{"count":20},{"count":5}]' }); + // Should not transform + expect(serverData).toEqual({ items: { '0': { count: 20 }, '1': { count: 5 } } }); + expect(objectCache).toEqual({ items: '{"0":{"count":20},"1":{"count":5}}' }); }); it('can commit json array with PushStatus offset fields', () => {