Skip to content

Commit

Permalink
Release 2.2.9
Browse files Browse the repository at this point in the history
Improve web platform support #13
  • Loading branch information
k-paxian committed Jan 29, 2023
1 parent 4edf5cc commit 64f9785
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 13 deletions.
4 changes: 4 additions & 0 deletions mapper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.9

* Improve web platform support #13

## 2.2.8

* Improve class instance creation error handling #211
Expand Down
5 changes: 0 additions & 5 deletions mapper/lib/src/mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,6 @@ class JsonMapper {

Map<Symbol, dynamic> _getNamedArguments(
ClassMirror cm, JsonMap jsonMap, DeserializationContext context) {
if (kIsWeb) {
// No named arguments in JS :(
return <Symbol, dynamic>{};
}

final result = <Symbol, dynamic>{};

_enumerateConstructorParameters(
Expand Down
7 changes: 6 additions & 1 deletion mapper/lib/src/model/type_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class DefaultTypeInfoDecorator implements ITypeInfoDecorator {
typeInfo.typeName == 'BigInt' || typeInfo.typeName == '_BigIntImpl';

bool isRegExp(TypeInfo typeInfo) =>
typeInfo.typeName == 'RegExp' || typeInfo.typeName == '_RegExp';
typeInfo.typeName == 'JSSyntaxRegExp' ||
typeInfo.typeName == 'RegExp' ||
typeInfo.typeName == '_RegExp';

bool isUri(TypeInfo typeInfo) =>
typeInfo.typeName == 'Uri' ||
Expand Down Expand Up @@ -108,11 +110,14 @@ class DefaultTypeInfoDecorator implements ITypeInfoDecorator {
typeInfo.isDynamic = typeName == 'dynamic';
typeInfo.isList = typeName.startsWith('_GrowableList<') ||
typeName.startsWith('List<') ||
typeName.startsWith('JSArray<') ||
isUnmodifiableListView(typeInfo) ||
isCastList(typeInfo);
typeInfo.isSet = typeName.startsWith('Set<') || isHashSet(typeInfo);
typeInfo.isMap = typeName == '_JsonMap' ||
typeName.startsWith('Map<') ||
typeName.startsWith('IdentityMap<') ||
typeName.startsWith('LinkedMap<') ||
isHashMap(typeInfo) ||
isLinkedHashMap(typeInfo) ||
isUnmodifiableMapView(typeInfo);
Expand Down
2 changes: 1 addition & 1 deletion mapper/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dart_json_mapper
version: 2.2.8
version: 2.2.9
description: >
This package allows programmers to annotate Dart objects in order to
serialize / deserialize them from / to JSON.
Expand Down
3 changes: 3 additions & 0 deletions perf-test/build.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
targets:
$default:
builders:
build_web_compilers:entrypoint:
generate_for:
- test/unit/*.dart
dart_json_mapper:
options:
iterables: List, Set
Expand Down
1 change: 1 addition & 0 deletions perf-test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dev_dependencies:
path:
build_runner:
build_test:
build_web_compilers:
test:
dependency_overrides:
unit_testing:
Expand Down
2 changes: 1 addition & 1 deletion perf-test/test/unit/_test.mapper.g.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file has been generated by the dart_json_mapper v2.2.7+5
// This file has been generated by the dart_json_mapper v2.2.8
// https://github.com/k-paxian/dart-json-mapper
// @dart = 2.12
import 'package:dart_json_mapper/dart_json_mapper.dart' show JsonMapper, JsonMapperAdapter, SerializationOptions, DeserializationOptions, typeOf;
Expand Down
2 changes: 1 addition & 1 deletion perf-test/test/unit/test.collections.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void testCollections() {
final target = JsonMapper.deserialize<HashMap<String, int>>(json)!;

// then
expect(json, '{"c":3,"a":1,"b":2}');
expect(json, kIsWeb ? '{"a":1,"b":2,"c":3}' : '{"c":3,"a":1,"b":2}');

expect(target, TypeMatcher<HashMap<String, int>>());
expect(target.containsKey('a'), true);
Expand Down
4 changes: 3 additions & 1 deletion perf-test/test/unit/test.converters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ void testConverters() {
expect(json, '"$source"');
expect(target.pattern, instance.pattern);
expect(target, TypeMatcher<RegExp>());
expect(target, instance);
if (!kIsWeb) {
expect(target, instance);
}
});

test('UriConverter', () {
Expand Down
23 changes: 20 additions & 3 deletions perf-test/test/unit/test.default.value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,29 @@ void testDefaultValue() {
final target = JsonMapper.serialize(instance,
SerializationOptions(indent: '', processAnnotatedMembersOnly: true));
// then
expect(target,
'{"cropArea":{"top":0.0,"left":1.0,"right":1.0,"bottom":0.0},"id":1}');
expect(
target,
kIsWeb
? '{"cropArea":{"top":0,"left":1,"right":1,"bottom":0},"id":1}'
: '{"cropArea":{"top":0.0,"left":1.0,"right":1.0,"bottom":0.0},"id":1}');
});

test('Serialize Immutable class with DefaultValue provided', () {
// given
final immutableJsonWeb = '''{
"cropArea": {
"top": 0,
"left": 1,
"right": 1,
"bottom": 0
},
"id": 1,
"name": "Bob",
"car": {
"modelName": "Audi",
"color": "green"
}
}''';
final immutableJson = '''{
"cropArea": {
"top": 0.0,
Expand Down Expand Up @@ -147,7 +164,7 @@ void testDefaultValue() {
final target = JsonMapper.deserialize<ImmutableDefault>(json)!;

// then
expect(targetJson, immutableJson);
expect(targetJson, kIsWeb ? immutableJsonWeb : immutableJson);

expect(target.id, 1);
expect(target.cropArea, TypeMatcher<CropArea>());
Expand Down

0 comments on commit 64f9785

Please sign in to comment.