Replies: 1 comment
-
|
I found a solution that almost works. I created a separate property for each of my non-symetric types. Then I updated the includeToJson and includeFromJson properties so that the origin is read from the server and origin_id is sent to the server. However, this doesn't work because the originToJson function must be static, and I can't access the origin of my LoadingList within a static function. I can't find a way for Freezed to serialize a computed value IE So how can I assign the originId property either automatically when the origin changes or when the toJson function is called? I don't want to maintain origin and originId separately. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a question that pertains to Freezed used with Json_serializable.
I created this freezed class that contains several attributes that are custom classes, such as origin and assignee. The backend provides the entire json for these classes and they are correctly decoding using their own fromJson factories.
When one of these properties is changed in the frontend I need to update the backend with the new value. However, the backend doesn't accept the entire assignee object. It instead wants a json key called "assignee_id" that contains the
uuidproperty from the assignee.As an example, when the data is requested from the backend it would look like this:
And when I send the request to update the LoadingList it would look like this:
If the keys of the json were the same when encoding/decoding then it wouldn't be a problem. I could created a JsonConverter that extracts the
origin.uuidfrom the origin object when the LoadingList is encoded. However, I don't see a way to modify the keys of the json inside the toJson function. Ideally I'd remove theoriginkey and add theorigin_idkey.All of my custom properties use the same format. They all need the key changed from
property -> property_idand they need a value ofproperty.uuid.Beta Was this translation helpful? Give feedback.
All reactions