We have the following simple webserver:
package spring;
import avro.BatteryEvent;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.Date;
@RestController
public class EnergyResourcesController {
private final Date date = new Date();
@PostMapping("/event/{uuid}")
BatteryEvent postBatteryEvent(
@PathVariable("uuid") String uuid,
@RequestBody BatteryEvent batteryEvent) throws IOException {
batteryEvent.setTime(date.getTime());
return batteryEvent;
}
}
It uses a BatteryEvent
, which is an Avro-generated class, which is built from the following Avro schema:
{
"namespace": "avro",
"type": "record",
"name": "BatteryEvent",
"fields": [
{
"name": "charging_source",
"type": [
"string",
"null"
]
},
{
"name": "processor4_temp",
"type": [
"int",
"null"
]
},
{
"name": "device_id",
"type": [
"string",
"null"
]
},
{
"name": "processor2_temp",
"type": [
"int",
"null"
]
},
{
"name": "processor1_temp",
"type": [
"int",
"null"
]
},
{
"name": "charging",
"type": [
"int",
"null"
]
},
{
"name": "current_capacity",
"type": [
"int",
"null"
]
},
{
"name": "inverter_state",
"type": [
"int",
"null"
]
},
{
"name": "moduleL_temp",
"type": [
"int",
"null"
]
},
{
"name": "moduleR_temp",
"type": [
"int",
"null"
]
},
{
"name": "processor3_temp",
"type": [
"int",
"null"
]
},
{
"name": "soC_regulator",
"type": [
"float",
"null"
]
},
{
"name": "time",
"type": [
"long",
"null"
],
"logicalType": "local-timestamp-millis"
}
]
}
We send the webserver the following JSON,
{
"charging_source": "utility",
"processor4_temp": 160,
"device_id": "18806072-81ca-48ed-b01a-b080f2d8a1fa",
"processor2_temp": 96,
"processor1_temp": 60,
"charging": -912,
"current_capacity": 10948,
"inverter_state": 1,
"moduleL_temp": 199,
"moduleR_temp": 91,
"processor3_temp": 152,
"soC_regulator": 26.598085
}
The problem is the BatteryEvent
that we receive has all null
values besides the charging
field, like so:
{"charging_source": null, "processor4_temp": null, "device_id": null, "processor2_temp": null, "processor1_temp": null, "charging": -261, "current_capacity": null, "inverter_state": null, "moduleL_temp": null, "moduleR_temp": null, "processor3_temp": null, "soC_regulator": null, "time": null}
My question is, why is this? All of the sent data is valid JSON, and our Avro class is valid as well. Our Spring Boot server is simple and valid code that was taken from Spring Boot's own documentation. I want the data which Spring Boot casts to the BatteryEvent
object to contain the values from the sent battery event JSON.