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

Problem with fromJson in web app #1072

Closed
Oskar888 opened this issue Apr 15, 2024 · 1 comment
Closed

Problem with fromJson in web app #1072

Oskar888 opened this issue Apr 15, 2024 · 1 comment
Assignees
Labels
bug Something isn't working needs triage

Comments

@Oskar888
Copy link

Oskar888 commented Apr 15, 2024

Describe the bug
I have a problem with the fromJson method in a web application hosted on firebase. I use flutter as the frontend and dart_frog as the backend, in both I use exactly the same model and send exactly the same data and when the frontend sends it to the backend, it receives it without any problem, but when the backend sends it to the frontend it throws an error like this on the screenshot.
Zrzut ekranu 2024-04-16 o 00 15 41

Note:
'1.' on screenshot is before jsonDecode
'2.' on screenshot is after jsonDecode
Uncaught TypeError occurs at MyModel.fromJson

And same model and same request in backend logs:
Zrzut ekranu 2024-04-16 o 00 27 59

To Reproduce

  1. Create model with union type using freezed.
  2. Build flutter web app and deploy it on firebase hosting.

Expected behavior
After building the web app and deploying it should work

@Oskar888 Oskar888 added bug Something isn't working needs triage labels Apr 15, 2024
@Oskar888
Copy link
Author

This is model:
@freezed
class BackendData with _$BackendData {
@JsonSerializable(explicitToJson: true)
const factory BackendData.deviceData({
@jsonkey(name: 'device_data') required final BackendDeviceData deviceData,
}) = _DeviceData;

const factory BackendData.deviceDataConfirmation({
@jsonkey(name: 'device_data_id') required final String deviceDataId,
}) = _DeviceDataConfirmation;

@JsonSerializable(explicitToJson: true)
const factory BackendData.result({
@jsonkey(name: 'result') required final BackendResult result,
}) = _Result;

const factory BackendData.ping({
@jsonkey(name: 'ping') required final bool ping,
}) = _Ping;

const factory BackendData.ready({
@jsonkey(name: 'ready') required final bool ready,
}) = _Ready;

factory BackendData.fromJson(Map<String, dynamic> json) => _$BackendDataFromJson(json);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants