I am facing an issue with my service method that saves a date on the server. When this method sends the date to the server, it includes fields with null values in the JSON. How can I exclude these fields with null values?
public create<T>(post: any): Observable<T> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
return this.httpClient
.post<T>(`${this.url}`, JSON.stringify(post), httpOptions)
.pipe(catchError((err, source) => this.responseHandler.onCatch(err, source)));
}
The JSON being sent to the server:
{
"name": "test",
"professionType":{
"id": null
},
"comment": null,
"organizationSpecialities":[
{
"speciality":{
"id": null
},
"effective": 2,
"effectiveDate":{
"startDate": null,
"endDate": "2019/12/01"
}
}
]
}
The desired JSON to be sent:
{
"name": "test",
"organizationSpecialities":[
"effective": 2,
"effectiveDate":{
"endDate": "2019/12/01"
}
}
]
}