Repository navigation
No deserialization found for type dynamic #2722
|
I want to return an endpoint with Map<String, dynamic> and I am sending the model I created on the serverpod side as you can see below, but I am getting the error "No deserialization found for type dynamic". Can't I return Map<String, dynamic> as the return type? Or is there a problem while sending the model? Here my endpoint: and console log No deserialization found for type dynamic
IDE: Android Studio, Thanks. |
Replies: 1 comment
|
Why do you want to return this JSON manually? You could just as easily create a model like so: class: MyResponse
fields:
userInfo: model:auth:userInfo?
verificationCode: String?
isDetectedNewDevice: bool
message: String
statusCode: intIf you use the generated class from the above definition, Serverpod will manage the Serialization for you. Hence you will not need to do any manual conversion and you get a typed interface! Endpoints also supports managing exceptions for you, you can simply throw a serializable exception and Serverpod will automatically send it to the client and throw it there! With this you could remove the statusCode field and simply throw an error instead in the error case. E.g. exception: MyException
fields:
message: StringA side note, it looks like you are building an endpoint for a specific user? If so I would recommend not sending the userId as a param. It means that anyone could send a request with someone else's userId and retrieve information about someone else, e.g. this is a security risk. Instead, you can get the userId from the authenticated user by looking at the session object. Like so: final auth = await session.authenticated;
final userInfoId = auth?.userId; |
dynamicis not supported as a type in either the models or endpoint params/return values.Why do you want to return this JSON manually? You could just as easily create a model like so:
If you use the generated class from the above definition, Serverpod will manage the Serialization for you. Hence you will not need to do any manual conversion and you get a typed interface!
See: https://docs.serverpod.dev/concepts/models
Endpoints also supports managing exceptions for you, you can simply throw a serializable exception and Serverpod will autom…