You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I am creating a class that will mostly map to a data class, encapsulating JSON response data from a REST API. However, the class will need to perform additional operations against the API in addition to storing the data. In order to perform these additional tasks the class needs to contain a reference to an HTTP session object, but this object is not intended to be serialized.
I've managed to get this mostly working by using some code that looks like this:
The problem case arises when I try to make the session field required as in @JsonKey(includeFromJson: false, includeToJson: false) required Session? session. Doing so produces an error that looks something like this:
Cannot populate the required constructor argument: session. It is assigned to a field not meant to be used in fromJson.
Describe the solution you'd like
I would like to be able to declare my class with a required field that must get populated during construction.
Describe alternatives you've considered
I've tried to come up with a way to define the JSON data class portion as a base class, and then define a derived class that extends this one which adds the required session object, but I kept hitting problems revolving around construction (ie: no generative constructors on the base classes etc.)
Additional context
N/A
The text was updated successfully, but these errors were encountered:
The Error you posted is from json_serializable, not freezed.
[SEVERE] json_serializable on lib/issue_1075.dart:
Cannot populate the required constructor argument: session. It is assigned to a field not meant to be used in fromJson.
package:freezed_issues/issue_1075.freezed.dart:126:9
╷
126 │ const _$MyObjImpl(
│ ^^^^^^^^^^^
╵
Is your feature request related to a problem? Please describe.
I am creating a class that will mostly map to a data class, encapsulating JSON response data from a REST API. However, the class will need to perform additional operations against the API in addition to storing the data. In order to perform these additional tasks the class needs to contain a reference to an HTTP session object, but this object is not intended to be serialized.
I've managed to get this mostly working by using some code that looks like this:
The problem case arises when I try to make the
session
field required as in@JsonKey(includeFromJson: false, includeToJson: false) required Session? session
. Doing so produces an error that looks something like this:Describe the solution you'd like
I would like to be able to declare my class with a required field that must get populated during construction.
Describe alternatives you've considered
I've tried to come up with a way to define the JSON data class portion as a base class, and then define a derived class that extends this one which adds the required session object, but I kept hitting problems revolving around construction (ie: no generative constructors on the base classes etc.)
Additional context
N/A
The text was updated successfully, but these errors were encountered: