Skip to content

Commit

Permalink
fix: Custom JSON encoder for List and Map doesn't work correctly in `…
Browse files Browse the repository at this point in the history
…full` mode (#789)
  • Loading branch information
mbfakourii authored Nov 15, 2022
1 parent 14be107 commit 7fb7ce6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [3.1.3](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-3.1.2...dart-3.1.3) (2022-11-15)

### Bug Fixes

* Custom JSON encoder for List and Map doesn't work correctly in `full` mode ([#788](https://github.com/parse-community/Parse-SDK-Flutter/issues/788))

## [3.1.2](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-3.1.1...dart-3.1.2) (2022-07-09)

### Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions packages/dart/lib/src/utils/parse_encoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ dynamic parseEncode(dynamic value, {bool full = false}) {

if (value is List) {
return value.map<dynamic>((dynamic value) {
return parseEncode(value);
return parseEncode(value, full: full);
}).toList();
}

if (value is Map) {
value.forEach((dynamic k, dynamic v) {
value[k] = parseEncode(v);
value[k] = parseEncode(v, full: full);
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: parse_server_sdk
description: Dart plugin for Parse Server, (https://parseplatform.org), (https://back4app.com)
version: 3.1.2
version: 3.1.3
homepage: https://github.com/parse-community/Parse-SDK-Flutter

environment:
Expand Down
50 changes: 50 additions & 0 deletions packages/dart/test/parse_encoder_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:parse_server_sdk/parse_server_sdk.dart';
import 'package:test/test.dart';

void main() {
test(
'should return expectedResult json when json has Nested map and list data.',
() async {
// arrange
await Parse().initialize(
'appId',
'https://test.parse.com',
debug: true,
// to prevent automatic detection
fileDirectory: 'someDirectory',
// to prevent automatic detection
appName: 'appName',
// to prevent automatic detection
appPackageName: 'somePackageName',
// to prevent automatic detection
appVersion: 'someAppVersion',
);

ParseObject parseObject2 = ParseObject("objectId2");
parseObject2.objectId = "objectId2";

// List and Map
parseObject2
.setAdd("dataParseObjectList", ["ListText1", "ListText2", "ListText3"]);
parseObject2.setAdd("dataParseObjectMap", {
'KeyTestMap1': 'ValueTestMap1',
'KeyTestMap2': 'ValueTestMap2',
'KeyTestMap3': 'ValueTestMap3',
});

// parseObject2 inside parseObject1
ParseObject parseObject1 = ParseObject("parseObject1");
parseObject1.objectId = "objectId1";
parseObject1.setAdd("dataParseObject2", parseObject2);

// desired output
String expectedResult =
"{className: parseObject1, objectId: objectId1, dataParseObject2: {__op: Add, objects: [{className: objectId2, objectId: objectId2, dataParseObjectList: {__op: Add, objects: [[ListText1, ListText2, ListText3]]}, dataParseObjectMap: {__op: Add, objects: [{KeyTestMap1: ValueTestMap1, KeyTestMap2: ValueTestMap2, KeyTestMap3: ValueTestMap3}]}}]}}";

// act
dynamic actualResult = parseEncode(parseObject1, full: true);

//assert
expect(actualResult.toString(), expectedResult);
});
}

0 comments on commit 7fb7ce6

Please sign in to comment.