我有一个包含java对象的类,它包含其他现在忽略的类
class A {
B b;
}
class B {
String name;
Object value; // value can be a string, list or int
//setters, getters for name
public void setValue(Object value) {this.value = value;}
public Object getValue() { return this.value;}
}
我正在使用jaxr将输入作为json输入到我的api,如下所示:
@Consumes(MediaType.APPLICATION_JSON)
public Response getData(A a) throws JsonProcessingException {
A.getB().getValue();
}
问题是getValue()
总是以ElementNSImpl
对象的形式返回,我想作为Java对象返回,以便我可以检查实例并相应地创建对象。
这是Json输入的样子:
{
b: {
"name": "product",
"value": "thisIsString" // than I want to create string class.
or
"value": ["item1", "item2"] // list class
or
"value": 232 // int class
}