Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5d299e0

Browse files
authoredMay 14, 2021
Correctly decode Map<String,double> when the input has int literals (google#894)
Prepare to release v4.1.2 Also fix directive ordering, which is now enforced Also add stable branch (v4_x) to test on CI Also update generated CI code with latest mono_repo
1 parent 1443303 commit 5d299e0

File tree

10 files changed

+147
-39
lines changed

10 files changed

+147
-39
lines changed
 

‎.github/workflows/dart.yml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Created with package:mono_repo v3.4.7
1+
# Created with package:mono_repo v4.0.0
22
name: Dart CI
33
on:
44
push:
55
branches:
66
- master
7-
- "3_x"
7+
- "4_x"
88
pull_request:
99
schedule:
1010
- cron: "0 0 * * 0"
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Cache Pub hosted dependencies
23-
uses: actions/cache@v2
23+
uses: actions/cache@v2.1.5
2424
with:
2525
path: "~/.pub-cache/hosted"
2626
key: "os:ubuntu-latest;pub-cache-hosted;dart:stable"
@@ -31,17 +31,17 @@ jobs:
3131
with:
3232
sdk: stable
3333
- id: checkout
34-
uses: actions/checkout@v2
34+
uses: actions/checkout@v2.3.4
3535
- name: mono_repo self validate
36-
run: pub global activate mono_repo 3.4.7
36+
run: pub global activate mono_repo 4.0.0
3737
- name: mono_repo self validate
3838
run: pub global run mono_repo generate --validate
3939
job_002:
4040
name: "analyzer_and_format; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
4141
runs-on: ubuntu-latest
4242
steps:
4343
- name: Cache Pub hosted dependencies
44-
uses: actions/cache@v2
44+
uses: actions/cache@v2.1.5
4545
with:
4646
path: "~/.pub-cache/hosted"
4747
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer"
@@ -54,7 +54,7 @@ jobs:
5454
with:
5555
sdk: "2.12.0"
5656
- id: checkout
57-
uses: actions/checkout@v2
57+
uses: actions/checkout@v2.3.4
5858
- id: _test_yaml_pub_upgrade
5959
name: "_test_yaml; pub upgrade --no-precompile"
6060
if: "always() && steps.checkout.conclusion == 'success'"
@@ -125,7 +125,7 @@ jobs:
125125
runs-on: ubuntu-latest
126126
steps:
127127
- name: Cache Pub hosted dependencies
128-
uses: actions/cache@v2
128+
uses: actions/cache@v2.1.5
129129
with:
130130
path: "~/.pub-cache/hosted"
131131
key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer"
@@ -138,7 +138,7 @@ jobs:
138138
with:
139139
sdk: dev
140140
- id: checkout
141-
uses: actions/checkout@v2
141+
uses: actions/checkout@v2.3.4
142142
- id: _test_yaml_pub_upgrade
143143
name: "_test_yaml; pub upgrade --no-precompile"
144144
if: "always() && steps.checkout.conclusion == 'success'"
@@ -209,7 +209,7 @@ jobs:
209209
runs-on: ubuntu-latest
210210
steps:
211211
- name: Cache Pub hosted dependencies
212-
uses: actions/cache@v2
212+
uses: actions/cache@v2.1.5
213213
with:
214214
path: "~/.pub-cache/hosted"
215215
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0"
@@ -222,7 +222,7 @@ jobs:
222222
with:
223223
sdk: "2.12.0"
224224
- id: checkout
225-
uses: actions/checkout@v2
225+
uses: actions/checkout@v2.3.4
226226
- id: _test_yaml_pub_upgrade
227227
name: "_test_yaml; pub upgrade --no-precompile"
228228
if: "always() && steps.checkout.conclusion == 'success'"
@@ -268,7 +268,7 @@ jobs:
268268
runs-on: ubuntu-latest
269269
steps:
270270
- name: Cache Pub hosted dependencies
271-
uses: actions/cache@v2
271+
uses: actions/cache@v2.1.5
272272
with:
273273
path: "~/.pub-cache/hosted"
274274
key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0"
@@ -281,7 +281,7 @@ jobs:
281281
with:
282282
sdk: dev
283283
- id: checkout
284-
uses: actions/checkout@v2
284+
uses: actions/checkout@v2.3.4
285285
- id: _test_yaml_pub_upgrade
286286
name: "_test_yaml; pub upgrade --no-precompile"
287287
if: "always() && steps.checkout.conclusion == 'success'"
@@ -327,7 +327,7 @@ jobs:
327327
runs-on: ubuntu-latest
328328
steps:
329329
- name: Cache Pub hosted dependencies
330-
uses: actions/cache@v2
330+
uses: actions/cache@v2.1.5
331331
with:
332332
path: "~/.pub-cache/hosted"
333333
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable;commands:test_2"
@@ -340,7 +340,7 @@ jobs:
340340
with:
341341
sdk: "2.12.0"
342342
- id: checkout
343-
uses: actions/checkout@v2
343+
uses: actions/checkout@v2.3.4
344344
- id: json_serializable_pub_upgrade
345345
name: "json_serializable; pub upgrade --no-precompile"
346346
if: "always() && steps.checkout.conclusion == 'success'"
@@ -359,7 +359,7 @@ jobs:
359359
runs-on: ubuntu-latest
360360
steps:
361361
- name: Cache Pub hosted dependencies
362-
uses: actions/cache@v2
362+
uses: actions/cache@v2.1.5
363363
with:
364364
path: "~/.pub-cache/hosted"
365365
key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:json_serializable;commands:test_2"
@@ -372,7 +372,7 @@ jobs:
372372
with:
373373
sdk: dev
374374
- id: checkout
375-
uses: actions/checkout@v2
375+
uses: actions/checkout@v2.3.4
376376
- id: json_serializable_pub_upgrade
377377
name: "json_serializable; pub upgrade --no-precompile"
378378
if: "always() && steps.checkout.conclusion == 'success'"
@@ -391,7 +391,7 @@ jobs:
391391
runs-on: ubuntu-latest
392392
steps:
393393
- name: Cache Pub hosted dependencies
394-
uses: actions/cache@v2
394+
uses: actions/cache@v2.1.5
395395
with:
396396
path: "~/.pub-cache/hosted"
397397
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1"
@@ -404,7 +404,7 @@ jobs:
404404
with:
405405
sdk: "2.12.0"
406406
- id: checkout
407-
uses: actions/checkout@v2
407+
uses: actions/checkout@v2.3.4
408408
- id: _test_yaml_pub_upgrade
409409
name: "_test_yaml; pub upgrade --no-precompile"
410410
if: "always() && steps.checkout.conclusion == 'success'"
@@ -454,7 +454,7 @@ jobs:
454454
runs-on: ubuntu-latest
455455
steps:
456456
- name: Cache Pub hosted dependencies
457-
uses: actions/cache@v2
457+
uses: actions/cache@v2.1.5
458458
with:
459459
path: "~/.pub-cache/hosted"
460460
key: "os:ubuntu-latest;pub-cache-hosted;dart:dev;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1"
@@ -467,7 +467,7 @@ jobs:
467467
with:
468468
sdk: dev
469469
- id: checkout
470-
uses: actions/checkout@v2
470+
uses: actions/checkout@v2.3.4
471471
- id: _test_yaml_pub_upgrade
472472
name: "_test_yaml; pub upgrade --no-precompile"
473473
if: "always() && steps.checkout.conclusion == 'success'"

‎json_serializable/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.1.2
2+
3+
- Correctly decode `Map<String, double>` when the input has `int` literals.
4+
15
## 4.1.1
26

37
- Allow the latest `package:build_config`.

‎json_serializable/lib/src/type_helpers/map_helper.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> {
9090

9191
if (!targetTypeIsNullable &&
9292
(valueArgIsAny ||
93-
simpleJsonTypeChecker.isAssignableFromType(valueArg))) {
93+
// explicitly exclude double since we need to do an explicit
94+
// `toDouble` on input values
95+
valueArg.isSimpleJsonTypeNotDouble)) {
9496
// No mapping of the values or null check required!
9597
final valueString = valueArg.getDisplayString(withNullability: false);
9698
return 'Map<String, $valueString>.from($expression as Map)';
@@ -179,3 +181,8 @@ Iterable<String> get _allowedTypeNames => const [
179181
'enum',
180182
'String',
181183
].followedBy(_instances.map((i) => i.coreTypeName));
184+
185+
extension on DartType {
186+
bool get isSimpleJsonTypeNotDouble =>
187+
!isDartCoreDouble && simpleJsonTypeChecker.isAssignableFromType(this);
188+
}

‎json_serializable/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_serializable
2-
version: 4.1.1
2+
version: 4.1.2
33
description: >-
44
Automatically generate code for converting to and from JSON by annotating
55
Dart classes.

‎json_serializable/test/enum_helper_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
@TestOn('vm')
6-
7-
import 'package:test/test.dart';
86
import 'package:json_serializable/src/type_helpers/enum_helper.dart';
7+
import 'package:test/test.dart';
98

109
void main() {
1110
group('expression test', () {

‎json_serializable/test/supported_types/input.type_map.g.dart

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:convert';
6+
7+
import 'package:test/test.dart';
8+
9+
import '../test_utils.dart';
10+
import 'input.type_map.dart';
11+
12+
void main() {
13+
test('SimpleClassOfStringToDouble', () {
14+
const value = {
15+
'value': {
16+
'double': 1.0,
17+
'int': 1,
18+
}
19+
};
20+
21+
final object = SimpleClassOfStringToDouble.fromJson(value);
22+
final encoded = loudEncode(object);
23+
24+
expect(
25+
encoded,
26+
loudEncode({
27+
'value': {
28+
'double': 1.0,
29+
// Note! Encoded as a double on output!
30+
'int': 1.0,
31+
}
32+
}),
33+
);
34+
35+
final object2 = SimpleClassOfStringToDouble.fromJson(
36+
jsonDecode(encoded) as Map<String, Object?>,
37+
);
38+
expect(loudEncode(object2), encoded);
39+
});
40+
41+
test('SimpleClassOfStringToInt', () {
42+
const value = {
43+
'value': {
44+
'int': 1,
45+
}
46+
};
47+
48+
final object = SimpleClassOfStringToInt.fromJson(value);
49+
final encoded = loudEncode(object);
50+
51+
expect(encoded, loudEncode(value));
52+
53+
final object2 = SimpleClassOfStringToInt.fromJson(
54+
jsonDecode(encoded) as Map<String, Object?>,
55+
);
56+
expect(loudEncode(object2), encoded);
57+
});
58+
59+
test('SimpleClassOfStringToNum', () {
60+
const value = {
61+
'value': {
62+
'double': 1.0,
63+
'int': 1,
64+
}
65+
};
66+
67+
final object = SimpleClassOfStringToNum.fromJson(value);
68+
final encoded = loudEncode(object);
69+
70+
expect(encoded, loudEncode(value));
71+
72+
final object2 = SimpleClassOfStringToNum.fromJson(
73+
jsonDecode(encoded) as Map<String, Object?>,
74+
);
75+
expect(loudEncode(object2), encoded);
76+
});
77+
}

‎json_serializable/test/utils_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
@TestOn('vm')
6-
7-
import 'package:test/test.dart';
8-
96
import 'package:json_serializable/src/utils.dart';
7+
import 'package:test/test.dart';
108

119
const _kebabItems = {
1210
'simple': 'simple',

‎mono_repo.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ github:
66
push:
77
branches:
88
- master
9-
- 3_x
9+
- 4_x
1010
pull_request:
1111
schedule:
1212
- cron: "0 0 * * 0"

‎tool/ci.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
#!/bin/bash
2-
# Created with package:mono_repo v3.4.7
2+
# Created with package:mono_repo v4.0.0
33

44
# Support built in commands on windows out of the box.
5+
# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter")
6+
# then "flutter" is called instead of "pub".
7+
# This assumes that the Flutter SDK has been installed in a previous step.
58
function pub() {
6-
if [[ $TRAVIS_OS_NAME == "windows" ]]; then
7-
command pub.bat "$@"
9+
if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then
10+
if [[ $TRAVIS_OS_NAME == "windows" ]]; then
11+
command flutter.bat pub "$@"
12+
else
13+
command flutter pub "$@"
14+
fi
815
else
9-
command pub "$@"
16+
if [[ $TRAVIS_OS_NAME == "windows" ]]; then
17+
command pub.bat "$@"
18+
else
19+
command pub "$@"
20+
fi
1021
fi
1122
}
1223
function dartfmt() {

0 commit comments

Comments
 (0)
Please sign in to comment.