dart-json-mapper
dart-json-mapper copied to clipboard
Can`t use JsonMapper in production build for web platform
Given this code
import 'package:dart_json_mapper/json_mapper.dart';
import 'package:dart_json_mapper/annotations.dart';
import 'main.reflectable.dart';
@jsonSerializable
class TridaA {
TridaA() {
print("TridaA constructed");
}
String prop;
}
void main() async {
// inicializace reflektoru
initializeReflectable();
print(".main");
jsonSerializable.annotatedClasses.forEach((cls) {
print("Annotated class ${cls.qualifiedName}");
});
print("allClasses ${jsonSerializable.annotatedClasses}");
var mirror = jsonSerializable.annotatedClasses.firstWhere((cm) {
print(" class ${cm.simpleName} ~ ${cm.reflectedType.toString()}");
return cm.simpleName == "TridaA";
});
print("Instance by reflection: ${mirror.newInstance("", [], {})}");
var map = Map<String, dynamic>.from({"b": Map<String, dynamic>.from({"prop": "test"})});
var instance = JsonMapper.instance
.deserializeObject(map, TridaA);
print("Instance by JsonMapper: ${instance}");
}
Everything is OK if it is built with dartdevc, but when compiled with dart2js by:
webdev serve web:43751 --hot-reload --release
with minification, it raise error:
Uncaught It seems your class 'minified:a6' has not been annotated with @jsonSerializable at Object.c (localhost:43751/main.dart.js:2719:3) at bX.a2 (localhost:43751/main.dart.js:5437:20) at bX.bB (localhost:43751/main.dart.js:5442:30) at localhost:43751/main.dart.js:6122:49 at ef.a (localhost:43751/main.dart.js:3678:72) at ef.$2 (localhost:43751/main.dart.js:3804:23) at Object.jI (localhost:43751/main.dart.js:3659:3) at Object.fD (localhost:43751/main.dart.js:6124:10) at localhost:43751/main.dart.js:6532:8 at localhost:43751/main.dart.js:6527:55
@fidlip Thank you for the fix. It's absolutely acceptable.
Thanks a lot!
Hi @k-paxian
I have the same problem when using generic types (https://github.com/k-paxian/dart-json-mapper/issues/101#issuecomment-1007344542)
flutter web
Hello, please solve this problem I need it
Hello @k-paxian , Hope you are fine :).
When i went into web production , the console output this one too :
Uncaught It seems your class 'minified:x<dynamic>' has not been annotated with @jsonSerializable
.
Then can't load and use the library .
Do you get any ideas ?
@jeansebastienZ sure, this issue needs some more love & attention. I'd like to mitigate it at least and this time I'm struggling to focus myself on other topics. (including latest tech layoffs, I couldn't donate extra more personal time on OSS, occasion by occasion now, small issues etc.)
Re @k-paxian , ✌🏽,
I tried avoiding minification with --profile however it still produce the error ( Uncaught It seems your class 'JSArray<dynamic>' has not been annotated with @jsonSerializable
) .
--profile mode still doing tree-shaking and there is no way to deactivate it right now.
As it is not possible to build web in Debug , right now it's not possible for us to use JSON MAPPER for web. If you get any solution you are welcome 👍🏾
Hello @k-paxian, Can you send me a mail please 😉 ?
@jeansebastienZ please try the latest version 2.2.9
and give more feedback
Hello @k-paxian ,
First thanks you for digging on this problem ✌🏽, as my team need this feature for going in production mode.
I tried with the last version :
I still get this in release mode ( by the way i did re-generate the main.mapper.g to be sure ) :
Minification is a separate issue, the goal of the release was green unit tests first.
I need this web platform support myself, particularly for the dart 3.0 capable to build web components for easy embedding. So eventually this issue would be resolved, but I cannot promise any timelines :shrug:
Re @k-paxian ,
Thanks you for the info ! I've just ran it in --profile mode and uploaded to a repository and it is working well ! Thanks you for your constant works on this repository .
Hi @k-paxian I used --profile mode but it has error like below, could you tell me how to fix?

Hello @likeconan , Did you update the version , clean your cache and regenerate the main.mapper.g ? Moreover are your sure every mdls you use are effectively used on a adapter before running your app ?
@jeansebastienZ Hi, I used dart_json_mapper with 2.2.9 version. And finally got the reason, it's because I uploaded into aws s3 and using cloudfront to host. When using s3 static website, everything works fine
Thank you for the workaround.
I'd also be interested in a fix for the release mode, since now my JavaScript File weighs around 6Mb which takes quite long to load. Thank you!
I'd be interested in taking a look into it. Yet I have no idea where to start, since there is no explicit web code. @k-paxian do you have a hint for me? Thank you :)
You can start from https://pub.dev/packages/build_web_compilers And making a failing unit test, after minification process.
I tried. But actually don't have a clue what I am doing 😬