k-paxian / dart-json-mapper

Serialize / Deserialize Dart Objects to / from JSON
https://pub.dev/packages/dart_json_mapper
Other
399 stars 33 forks source link

It seems your class `_GrowableList<String>` has not been annotated with `@jsonSerializable` #171

Closed peterweb2005 closed 2 years ago

peterweb2005 commented 2 years ago

as title development time is good

thanks

k-paxian commented 2 years ago

Unfortunately, this tells me nothing. Can you provide a localized reproducible code snippet to illustrate the issue?

peterweb2005 commented 2 years ago

need much much times, but

is that related to this:

@jsonSerializable
@Json(
  ignoreNullMembers: true,
  valueDecorators: Test.valueDecorators,
)
class Test {
  //
  List<List<String>>? timetable;

  static Map<Type, ValueDecoratorFunction> valueDecorators() => {
        typeOf<List<List<String>>>(): (value) => value.cast<List<String>>(),
        typeOf<List<String>>(): (value) => value.cast<String>()
      };
}
peterweb2005 commented 2 years ago

screen capture stacktrace https://ibb.co/S0vQVCT

peterweb2005 commented 2 years ago

quite sure the problem related to valueDecorators,

i just commented the field & related stuffs, generate files, build apk, install, run the alert has not been displayed

Groseuros commented 2 years ago

Hello,

First of all, thank you for your work !

I'm facing exactly the same issue with my release build for both iOS and Android (working fine in debug / profile mode). Last working build was build Sept 30.

When I call JsonMapper.serialize(mySuperClass) I got this exception : It seems your class _GrowableList< anotherClass > has not been annotated with @JsonSerializable.

I tried to downgrade dart_json_mapper: ^2.1.16 to ^2.1.2, dart_json_mapper_flutter: ^2.0.1 to ^2.0.0 and build_runner: ^2.1.4 to ^2.1.1 and regenerated mapper.g.dart file (my previous working build config) but the issue is still here.

I also tried to downgrade Flutter v2.5.3 to v2.5.2 and tried to build with --no-shrink flag but same result.

How can I help you to investigate ?

k-paxian commented 2 years ago

Thank you both for reporting that 🤗 I hope I'll have enough time to nail it down. Not promising it'll be blazingly fast, but it will be fixed anyway.

Groseuros commented 2 years ago

Update:

I forgot to remove the '^' when I downgraded dart_json_mapper to 2.1.2 and and dart_json_mapper_flutter to 2.0.0. I did it in the right way and it's working again.

I'll try each version tonight to figure out which one introduces the issue.

Groseuros commented 2 years ago

Ok so... I can't upgrade package above v2.1.2 otherwise my app release build will trigger the exception, which sounds really strange to me.

Maybe I missed something with my config ?

MainClass:

@jsonSerializable
@Json(valueDecorators: MainClass.valueDecorators)
class MainClass {
  static Map<Type, ValueDecoratorFunction> valueDecorators() => {
        typeOf<List<OtherClassA>>(): (value) => value.cast<OtherClassA>(),
        typeOf<Map<String, List<OtherClassB>>>(): (value) =>
            value.cast<String, List<OtherClassB>>(),
        typeOf<List<OtherClassB>>(): (value) => value.cast<OtherClassB>()
      };

  List<OtherClassA> listOfClassA = [];
  Map<String, List<OtherClassB>> mapOfListsOfClassB =
      <String, List<OtherClassB>>{};

  Future<void> fillfromJson(Map<String, dynamic> json) async {
     ...
  }
}

OtherClassA:

@jsonSerializable
class OtherClassA {
  String name = '';
  int number = 0;

  void fillFromJson(Map<String, dynamic> json) {
    ...
  }
}

OtherClassB:

@jsonSerializable
class OtherClassB {
 [endless list of properties]

 [some methods]
}
jiechic commented 2 years ago

it is same error on my release build with flutter 2.5.3

the error begin when flutter update 2.5.x from 2.2.x