I have a situation where my typescript frontend is communicating with my java backend using REST. Recently, I added a new simple rest endpoint but encountered an issue when trying to cast the sent object properly because the body being sent is a LinkedHashMap.
service.ts
createEvent(event: CustomerEvent): Observable<HttpResponse<CustomerEvent>> {
return this.http.post<CustomerEvent>(this.eventUrl, event, { observe: 'response' });
}
customer-event-model.ts
export class CustomerEvent {
constructor(public customer: ICustomer, public event: String) {}
}
customer.model.ts
export interface ICustomer {
id?: number;
name?: string;
email?: string;
address?: string;
}
export class Customer implements ICustomer {
constructor(public id?: number, public name?: string, public email?: string, public address?: string) {}
}
Rest
public ResponseEntity<Object> addCustomerEvent(@RequestBody Object customerEvent) {
log.info("~REST request to create new event " + customerEvent.toString());
CustomerEvent e = (CustomerEvent) customerEvent; // <<---- FAILS cannot cast LinkedHashMap to CustomerEvent
}
Does anyone have insight into why it's sending a LinkedHashMap instead of the expected type?
Appreciate any help. Thank you!