0
我收到提示com.kp.schema.Value」被代"java.lang.Object", but "com.kp.schema.Value" is bound to an anonymous type..
代java.lang.Object繼承綁定到一個匿名類型
我使用CXF JSONProvider試圖元帥Java對象的JSONObject,我希望JSON對象爲
{
"KpJSON":
{
"header":
{
"cmd_resource": "commd",
"cmd_action": "PUT",
},
"parameters":
[
{
"name": "p1",
"syntax": "string",
"value": "text1"
},
{
"name": "p2",
"syntax": "integer",
"value": 1
},
{
"name": "input",
"syntax": "container",
"value":
[
{
"name": "ch1",
"syntax": "string",
"value": "file"
},
{
"name": "ch2",
"syntax": "boolean",
"value": false
}
]
}
]
}
}
我paramters.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"name",
"syntax",
"value"
})
@XmlRootElement(name = "parameters")
public class Parameters {
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected SyntaxType syntax;
@XmlElement(required = true)
protected List<Value> value;
//getters and setters
}
Value.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"name",
"syntax",
"value"
})
@XmlRootElement(name = "value")
public class Value {
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected SyntaxType syntax;
@XmlElement(required = true)
protected List<Value> value;
//getters and setters
}
當我試圖改變列表類型來價值Paramters.java
和改性Value.java
到以下
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"content"
})
@XmlRootElement(name = "value")
public class Value {
@XmlElementRefs({
@XmlElementRef(name = "name", namespace = "http://kp.com/schema/", type = JAXBElement.class),
@XmlElementRef(name = "syntax", namespace = "http://kp.com/schema/", type = JAXBElement.class),
@XmlElementRef(name = "value", namespace = "http://kp.com/schema/", type = Value.class)
})
@XmlMixed
protected List<Object> content;
// getters and setters
}
並試圖創建一個對象,如下所示,輸出是空的用於容器。
Parameters parameters3 = new Parameters();
parameters3.setName("K3");
parameters3.setSyntax(SyntaxType.CONTAINER);
Value val2 = new Value();
val2.getContent().add("sdfsdfs");
QName qname= new QName("");
JAXBElement kpsyntax = new JAXBElement(qname, SyntaxType.class, SyntaxType.CONTAINER);
kpsyntax.setValue(SyntaxType.CONTAINER);
Value val3 = new Value();
val2.getContent().add(kpsyntax);
parameters3.getValue().add(val3);
response.setHeader(header);
response.getParameters().add(parameters3);
JSON輸出是:
{"KpJSON":{"header":{"cmd_resource":"command","cmd_action":"PUT"},"parameters":{"name":"K3","syntax":"container","value":""}}}
有人可以幫我解決這個問題或任何建議
你有兩個'class Value',哪一個是'com.kp.schema.Value'? – Ilya