I'm building an Angular app that communicates with a restful API written with the Spring Framework.
My class hierarchy is something like this:
class Resource
class FileResource extends Resource
class DbResource extends Resource
class DbFileResource extends DbResource
class DbServerResource extends DbResource
and I'm sending such a json object in my post request for example, which suites the DbServerResource in my class hierarchy:
{
"resourceName": "Res2",
"resourceType": "DB_SERVER",
"dbms": "DB2",
"dbName": "SHOP",
"host": "<some ip>",
"port": 50000,
"userName": "user",
"password": "password"
}
In my controller I have a I have addResource
method:
@RequestMapping (method = RequestMethod.POST, value="/resource")
private void addResource(@RequestBody Resource resource)
And I have a Factory class that I'm calling to retrieve the exact object to work with by using instanceof
:
public ResourceId getResourceId(Resource res){
if (res== null){
return null;
}....
But when sending my request I am getting a NullPointerException:
java.lang.NullPointerException com...ResourceManager.validateResourceId(ResourceManager.java:861) com...management.resource.manager.ResourceManager.addResource(ResourceManager.java:127)
Seems that the Factory is not managing to recognize the relevant object and returning null! How shall spring recognize to which object it should map the json?! Or am I doing something else wrong!