Skip to content

fix: Custom JSON encoder for List and Map doesn't work correctly in full mode #789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
}