Getting Useful Untagged Enum Errors in Axum

How do I get more useful json validation errors when deserializing untagged enums? Currently I get this error message when the deserialized request body doesn't match one of the untagged enums:

Failed to deserialize the JSON body into the target type: data.attributes: data did not match any variant of untagged enum FoodData at line 8 column 5

I want a more detailed error on why it fails like this:

Failed to deserialize the JSON body into the target type: data: missing field `attributes` at line 8 column 5

I'm using the following type definition in the function for deserializing the payload:

payload: Result<Json<FoodData>, JsonRejection>

You can check either deserr or serde_path_to_error.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.