Description
I have come across a really strange incident that has made me rack my brains until I have been able to identify the origin of it.
I was working with the package in a new project and, tired of writing the toJson and fromJson methods in the classes, I have looked for extensions for Android Studio that would do the heavy lifting of creating this code.
The point is that in several of the extensions I have used I was getting code snippets like this:
Map<String, dynamic> toJson(instance) => _$UserJWTToJson(this);
Whatever I did, I always got the same error:
Converting object to an encodable object failed: Instance of 'XXX'
Where is the problem? The problem is that the extensions were adding an extra parameter "instance
" in the toJson
method:
Map<String, dynamic> toJson() => _$UserJWTToJson(this);
I suspect that, in the past, it was necessary to include this parameter and that, for some reason, the method with this parameter is not recognized by the library, thus generating the previous errors (which, on the other hand, could be improved).
The key points are:
- Was this parameter required in the past?
- Is it still required? Is this some kind of regression?
- If it is no longer necessary to include the instance parameter, would it be possible to make the library detect this method and launch some kind of warning?
It is clear that the extensions for IDE should be improved and updated, but if this is something that can occur for example when updating the version of the library, perhaps there should be some kind of control.
(My apologies if this is already documented and I have not seen it).