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

class with getter field throws FieldNotFoundException when using fromMap/fromJson #42

Open
copydog opened this issue Mar 12, 2019 · 5 comments
Labels

Comments

@copydog
Copy link

copydog commented Mar 12, 2019

I read the generated code, and the SerializableMap's code
please allow me using the easiest way

  1. fromMap method will try to assign getter with value, because it uses class mirror fields as the list, and class mirror fields contains getter field.
  2. []= method will throw FieldNotFoundException when unsupported key is given
  3. So, fromMap will throw FieldNotFoundException, when getter field exists.
@luisvt
Copy link
Collaborator

luisvt commented Mar 13, 2019

Could you show me your code?

@luisvt
Copy link
Collaborator

luisvt commented Mar 14, 2019

Sorry, now I understand the error. By the moment you only have three options:

  1. You can add a setter so dson always find it
  2. You add @ignore annotation to the getter and it should be ignored by dson.
  3. You could override the addAll method so it looks something like next:
@serializable
class Person extends _$PersonSerializable {
  int _id;
  int get id => _id;

  @override
  addAll(Map map) => PersonClassMirror.setters.forEach((setter) => this[setter] = map[setter]);
}

I'm going to fix this in future versions.

@luisvt luisvt changed the title class with getter field will FieldNotFoundException when using fromMap/fromJson class with getter field throws FieldNotFoundException when using fromMap/fromJson Mar 20, 2019
@luisvt luisvt added the wontfix label Mar 20, 2019
@luisvt luisvt closed this as completed Mar 20, 2019
@HonzaKopecky
Copy link

I think that the problem still persists. And using @ignore did not work for me. Getters like the following will still get serialized but it fails once object is being reconstructed.

@ignore
bool get isRunning => status == Task.RUNNING;

@ignore
bool get isPaused => status == Task.PAUSED;

@luisvt luisvt reopened this Oct 3, 2019
@mitty1987
Copy link

@luisvt Can the throwfieldnotfoundexception be removed?

@luisvt
Copy link
Collaborator

luisvt commented May 2, 2020

What do you mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants