I have a TypeScript object representing a user, with an id: number
. However, when this id is passed through axios, it is being parsed as a string internally which is causing issues with my server. I need to correct this issue.
The axios call I am making looks like this :
axios.post(
${url}
, user, { withCredentials: true });
and the User object is defined as follows :
export default class User {
Id: number;
Username: string;
Password: string;
constructor(Id: number, Username: string, Password: string) {
this.Id = Id;
this.Username = Username;
this.Password = Password;
}
}
After parsing, the object looks like this :
"{"Id":"1337","Username":"test","Password":"admin"}"
The expected output should be in this format :
"{"Id":1337,"Username":"test","Password":"admin"}"
My initial solution was to manually build the JSON object and use stringify, but since axios also uses stringify internally, this approach did not work as intended.