From 94155ce4057b42e9866439f0d40c658852ccf8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Wed, 27 Aug 2025 09:55:31 +0100 Subject: [PATCH 1/3] Fix non-proto3 JSON format double decoding When the field type is a proto `float` or `double` we always use a Dart `double` for the value. Trying to set the field an `int` causes an assertion failure in `FieldSet`. This code is also a bit inconsistent in itself: when the jspblite2 value is a string it decodes as `double`, but when it's a number it tries to convert to an `int`. So if the value is a string `"1"` it stores as `double` but if it's the number `1` it tries to convert to double. This isn't an issue with dart2js as with dart2js `int` and `double` are the same thing, but it causes assertion failures when this library is used with dart2wasm which distinguishes `int`s and `double`s. Fix by always storing proto `float`s and `double`s as Dart `double`s. cl/799924250 --- protobuf/lib/src/protobuf/json/json_web.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf/lib/src/protobuf/json/json_web.dart b/protobuf/lib/src/protobuf/json/json_web.dart index 6f3934bb..fa2354eb 100644 --- a/protobuf/lib/src/protobuf/json/json_web.dart +++ b/protobuf/lib/src/protobuf/json/json_web.dart @@ -389,7 +389,7 @@ Object? _convertRawJsValue( // Allow quoted values, although we don't emit them. if (value.isA()) { final jsNum = value._as(); - return _Number._isInteger(jsNum) ? jsNum.toDartInt : jsNum.toDartDouble; + return jsNum.toDartDouble; } else if (value.isA()) { return double.parse(value._as().toDart); } From d177538aaa4be4f62514663c8e684f33052c6494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Wed, 27 Aug 2025 09:57:17 +0100 Subject: [PATCH 2/3] Update changelog --- protobuf/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/protobuf/CHANGELOG.md b/protobuf/CHANGELOG.md index 0342de99..42956c78 100644 --- a/protobuf/CHANGELOG.md +++ b/protobuf/CHANGELOG.md @@ -3,9 +3,12 @@ * Improve performance of `GeneratedMessage.deepCopy`. ([#742]) * Fix unknown enum handling in `GeneratedMessage.mergeFromProto3Json` when the `ignoreUnknownFields` optional argument is `true`. ([#853]) +* Fix decoding doubles in `GeneratedMessage.mergeFromJson` and + `GeneratedMessage.mergeFromJsonMap` with dart2wasm. ([#1043]) [#742]: https://github.com/google/protobuf.dart/pull/742 [#853]: https://github.com/google/protobuf.dart/pull/853 +[#1043]: https://github.com/google/protobuf.dart/pull/1043 ## 4.2.0 From 02f8c9c60d562656f25cb0070a4ac59d4291d853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Thu, 28 Aug 2025 09:06:47 +0100 Subject: [PATCH 3/3] Revert CHANGELOG --- protobuf/CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/protobuf/CHANGELOG.md b/protobuf/CHANGELOG.md index 42956c78..0342de99 100644 --- a/protobuf/CHANGELOG.md +++ b/protobuf/CHANGELOG.md @@ -3,12 +3,9 @@ * Improve performance of `GeneratedMessage.deepCopy`. ([#742]) * Fix unknown enum handling in `GeneratedMessage.mergeFromProto3Json` when the `ignoreUnknownFields` optional argument is `true`. ([#853]) -* Fix decoding doubles in `GeneratedMessage.mergeFromJson` and - `GeneratedMessage.mergeFromJsonMap` with dart2wasm. ([#1043]) [#742]: https://github.com/google/protobuf.dart/pull/742 [#853]: https://github.com/google/protobuf.dart/pull/853 -[#1043]: https://github.com/google/protobuf.dart/pull/1043 ## 4.2.0