I have a java rest service that returns the following json:
Json Output
{
"description": "Temperature Sensor",
"symbol": "°C",
"name": "degree celsius",
"maxMeasure": {
"quantity": 12.8,
"name": "degree celsius",
"symbol": "°C",
"dateTime": "2018-03-15T12:38:23"
},
"measure": {
"quantity": 11.1,
"name": "degree celsius",
"symbol": "°C",
"dateTime": "2018-03-15T18:34:27"
},
"minMeasue": {
"quantity": 5.8,
"name": "degree celsius",
"symbol": "°C",
"dateTime": "2018-03-15T04:09:24"
},
"conversionFactor": 1
}
through this angular service i call the endpoint :
SensorService.ts
getSensor(sensorId: string): Observable<Sensor> {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('token', 'token');
headers.append('sensorId', sensorId);
headers.append('unitMeasureId', '1');
const options = new RequestOptions({ headers: headers });
return this._http.get(this._sensorurl, options)
.map(data => <Sensor> data.json())
.do(data => console.log(data));
}
and i map the result in this classes:
Sensor.ts
export class Sensor {
description: string;
symbol: string;
name: string;
maxMeasure: Measure;
measure: Measure;
minMeasue: Measure;
conversionFactor: number;
}
Measure.ts
export class Measure {
quantity: string;
name: string;
symbol: string;
dateTime: string;
}
with this statement:
sensor.component.ts
ngOnInit(): void {
this._sensor.getSensor(this.route.snapshot.paramMap.get('id'))
.subscribe(sensor => this.sensor = sensor);
}
the json is correctly read because by the console I can read it, but when it is mapped on the Sensor object give an undefined output.
where is that wrong?