I have a class Car, whose properties are String tyre, and Engine engine. and Engine is an abstract class that is been extended by Class Electric and Class Mechanical. Class Electric has property String battery, and Class Mechanical has property String piston.
Code for each class are:
class Car:
package com.kri.demo;
public class Car {
String tyre;
Engine engine; //abstract class
//getters and setters...
}
Class Engine:
package com.kri.demo;
public abstract class Engine {
String brand;
//getters and setters
}
Class Mechanical :
package com.kri.demo;
public class Mechanical extends Engine{
String pistonSize;
}
Class Electric:
package com.kri.demo;
public class Electric extends Engine{
String batteryCap;
}
I want to use class car in @RequestBody, I need to make a json request to post a information about Car. How can I make a json request for the inherited class Electric or Mechanical within json object Car?
"car":{
"tyre" : "goodDear",
"engine": ???
}