I am getting an instance of Serializable
out of some internal APIs. The Serializable
instance is actually Long
or String
, etc. Is there a way to make a DTO that can handle this situation? Using private Serializable value;
the JSON ends up with value: {}
.
UPDATE
Here is a reduced example of the code in question:
@Controller
public class SomeController
{
//...
public MyDto getInfo(Long id)
{
MyDto result = new MyDto();
Serializable obj = svc.getInfo(id);
// obj is either Long, or String, or one of few more fundamental Java types
result.setValue(obj);
return result;
}
}
public class MyDto
{
private Serializable value;
public void setValue(Serializable info)
{
this.value = value;
}
public Serializable getValue()
{
return value;
}
}
UPDATE 2
I have found the answer to my problem here: https://stackoverflow.com/a/20494813/341065