I have two POJO classes.
Class 1 is Engine.java:
private String engineId;
public String getEngineId(){
return this.engineId;
}
public void setEngineId(String engineId){
this.engineId = engineId;
}
The Second POJO class is Vehicle.java:
private String type;
private String manufacturer;
private Engine engine;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public Engine getEngine() {
return engine;
}
public void setEngine(Engine engine) {
this.engine = engine;
}
I have a REST Controller for providing information of Vechicles (RequestMethod.GET):
@RequestMapping(method = RequestMethod.GET)
public Vehicle getVechileDetails(Vehicle inputVehicle){
Vehicle vehicle = new Vehicle();
// some processing
return vehicle;
}
When I hit this service and provide the Request parameter as type or manufacturer, then the Spring creates the Vehicle object and populates the value of type and manufacturer. But if I provide the value of engineId, then the Spring is not able to create the Engine object such that vehicle.getEngine().getEngineId() != null
Is there any way in which if I invoke my Rest Service like:
http://localhost:8080/Controller/getVehicleDetails?engineId=12345
then the Vehicle is created with Engine having the value of engineId ?