Skip to content
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

Can`t use JsonMapper in production build for web platform #13

Open
fidlip opened this issue Mar 13, 2019 · 20 comments
Open

Can`t use JsonMapper in production build for web platform #13

fidlip opened this issue Mar 13, 2019 · 20 comments
Assignees
Labels
bug Something isn't working flutter.web issue occurs only in flutter web target

Comments

@fidlip
Copy link

fidlip commented Mar 13, 2019

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 fidlip changed the title Cant use JsonMapper in production build Can`t use JsonMapper in production build Mar 14, 2019
@k-paxian k-paxian self-assigned this Mar 15, 2019
@k-paxian k-paxian added the bug Something isn't working label Mar 15, 2019
@k-paxian
Copy link
Owner

@fidlip
Thank you for the fix. It's absolutely acceptable.

@fidlip
Copy link
Author

fidlip commented Mar 16, 2019

Thanks a lot!

@masoodmrx
Copy link

masoodmrx commented Jan 15, 2022

Hi @k-paxian
I have the same problem when using generic types (#101 (comment))
flutter web
image

@masoodmrx
Copy link

Hello, please solve this problem
I need it

@k-paxian k-paxian reopened this Jan 17, 2022
@k-paxian k-paxian added the flutter.web issue occurs only in flutter web target label Jan 21, 2022
@jeansebastienZ
Copy link

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 ?

@k-paxian
Copy link
Owner

@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.)

@jeansebastienZ
Copy link

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 👍🏾

@jeansebastienZ
Copy link

Hello @k-paxian,
Can you send me a mail please 😉 ?

@k-paxian k-paxian changed the title Can`t use JsonMapper in production build Can`t use JsonMapper in production build for web platform Jan 29, 2023
k-paxian added a commit that referenced this issue Jan 29, 2023
Improve web platform support #13
@k-paxian
Copy link
Owner

k-paxian commented Jan 29, 2023

@jeansebastienZ please try the latest version 2.2.9 and give more feedback

@jeansebastienZ
Copy link

jeansebastienZ commented Jan 29, 2023

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 :
Capture d’écran 2023-01-29 à 19 40 15
I still get this in release mode ( by the way i did re-generate the main.mapper.g to be sure ) :
Capture d’écran 2023-01-29 à 20 09 19

@k-paxian
Copy link
Owner

Minification is a separate issue, the goal of the release was green unit tests first.

@k-paxian
Copy link
Owner

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 🤷

@jeansebastienZ
Copy link

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 .

@likeconan
Copy link

likeconan commented Jan 30, 2023

Hi @k-paxian I used --profile mode but it has error like below, could you tell me how to fix?

image

@jeansebastienZ
Copy link

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 ?

@likeconan
Copy link

@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

@ma-pe
Copy link

ma-pe commented Apr 16, 2023

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!

@ma-pe
Copy link

ma-pe commented Apr 19, 2023

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 :)

@k-paxian
Copy link
Owner

You can start from https://pub.dev/packages/build_web_compilers
And making a failing unit test, after minification process.

@ma-pe
Copy link

ma-pe commented Apr 27, 2023

I tried. But actually don't have a clue what I am doing 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working flutter.web issue occurs only in flutter web target
Projects
None yet
Development

No branches or pull requests

6 participants