-
-
Notifications
You must be signed in to change notification settings - Fork 691
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
Server Function taking struct with empty Vec fails to deserialize #1741
Comments
I have encountered with the same problem. A empty vector cause this error 😥 |
Some encodings have no method for displaying an empty list of items. Annotate your struct definition with #[derive(Serialize, Deserialize)]
struct MyData {
#[serde(default)]
some_list: Vec<Entry>,
} For what it is worth, this is expected behavior of serde. |
I missed the fact that this was a nested struct originally. Yes I think @ChristopherPerry6060 has the correct answer here: add @dpytaylo You say you've encountered the same issue: Is that similarly on a nested struct like this? (I say "nested" because the server functions arguments are, themselves, built into a struct.) It's also possible this is |
No, I use just a vector: #[server(SendChatMessage, "/api")]
pub async fn send_chat_message(messages: Vec<String>, new_message: String) -> Result<String, ServerFnError> {
} |
Yeah so ultimately it's just this known issue with I guess we could add an attribute to the server fn macro that passes through |
This is closed by #1762: You can add |
Describe the bug
If a server function takes a
MyData
struct that contains aVec
, and then that server function is called with an emptyVec
, it fails deserialization saying the whole field is missing.Fails with:
Looking at the data sent over the network, it seems that it uses Multipart Encoding and sends the parameters as:
and when the list is empty, it just doesn't contain any entries for it. This is likely the cause of the issue.
Changing the encoding of the server function to
Cbor
works, so it's specific to theUrl
encoding.Leptos Dependencies
To Reproduce
Expected behavior
Server function is correctly called and deserializes its arguments
The text was updated successfully, but these errors were encountered: