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
Array values cast to string
when length of array is 1
#1
Comments
Short answer Long answer There is no way for the server to know that you have sent an array, therefore the field name has to indicate that by suffixing the brackets. However, when you send multiple values, they turn out to be like this in the payload |
Thank you for the explanation. Would you like this behaviour to be documented in the API client section? |
Not sure. Coz, it is more of an HTTP thing. If you make a call using HTML forms, or Insomnia, then the behavior will be the same. So it is not specific to the API client. |
Okay. Thanks. |
Description
I noticed that when an array value is assigned to a field and the length of the array is
1
, the value is cast to a string.For example:
Within a test,
userRoles
is an arraybut in the controller, it is received as:
However, if the length of the array is more than
1
, an array is received in the controller.Package version
Relevant Information
I'm also not certain if this behaviour is caused by Adonisjs Bodyparser or the Japa's API client. But I want to believe that this kind of behaviour won't occur within the Bodyparser middleware.
The text was updated successfully, but these errors were encountered: