I am trying to figure out if there is a way to instantiate a new object dynamically based on user input in java.
E.g.
I have 3 entities/objects
public class Item {}
public class Room {}
public class Location {}
In a form the user would fill out a input field called "id='objecttype'" and it would be sent to a controler. The controller would dynamically return a object based on the String value.
e.g.
If user types in Item, it will generate a Item object and return it as such. Same goes if the user types in Room, it will instantiate a Room object and return new Room() object, and finally same for Location where user types in Location and java returns a new Location() object.
E.G. of controller
@RequestMapping(value = "/retVal", method = /*POST Type*/)
public Object retVal(@RequestParameter("objecttype") String type) {
// here the logic would determine which object would get returned
// if type is Item
// return new Item();
// if type is Room
// return new Room();
// if type is Location
// return new Location();
return null;
}