您好,我正在尝试在hp alm中记录缺陷。我写了一个java程序。这给了我错误500。因为我想把同一个身份证
我获取了缺陷url:您好,我正在尝试在hp alm中记录缺陷。我写了一个java程序。这给了我错误500。因为我想把同一个身份证,java,xml,eclipse,marshalling,Java,Xml,Eclipse,Marshalling,我获取了缺陷url: String defectUrl = conn.buildEntityCollectionUrl("defect"); defectUrl += "/98"; Map<String, String> requestHeaders = new HashMap<String, String>(); requestHeaders.put("Accept", "application/xml"); Response
String defectUrl = conn.buildEntityCollectionUrl("defect");
defectUrl += "/98";
Map<String, String> requestHeaders = new HashMap<String, String>();
requestHeaders.put("Accept", "application/xml");
Response res = conn.httpGet(defectUrl, null, requestHeaders);
然后更改字段值:
List<Field> fields = entity.getFields().getField();
for (Field f : fields) {
if (f.getName().equalsIgnoreCase("id"))
{
int i=f.hashCode();
System.out.println(i);
f.getValue().clear();
f.setName("");
}
}
抛出错误作为对象字段不应该存在,并且不能得到我应该放置什么来代替字段
我的整个Marshalingutils课程如下:
package org.hp.qc.web.restapi.docexamples.docexamples.infrastructure;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.Marshaller;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
//import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
public class EntityMarshallingUtils {
private EntityMarshallingUtils() {}
@SuppressWarnings("unchecked")
public static <T> T marshal(Class<T> c, String xml) throws JAXBException {
T res;
if (c == xml.getClass()) {
res = (T) xml;
}
else {
JAXBContext ctx = JAXBContext.newInstance(c);
Unmarshaller marshaller = ctx.createUnmarshaller();
res = (T) marshaller.unmarshal(new StringReader(xml));
}
return res;
}
@SuppressWarnings("unchecked")
public static <T> String unmarshal(Class<T> c, Object o) throws Exception {
JAXBContext ctx = JAXBContext.newInstance(c);
Marshaller marshaller = ctx.createMarshaller();
StringWriter entityXml = new StringWriter();
marshaller.marshal(o, entityXml);
String entityString = entityXml.toString();
return entityString;
}
}
package org.hp.qc.web.restapi.docexamples.docexamples.infrastructure;
导入java.io.StringReader;
导入java.io.StringWriter;
导入javax.xml.bind.Marshaller;
导入javax.xml.bind.JAXBContext;
导入javax.xml.bind.JAXBException;
//导入javax.xml.bind.Marshaller;
导入javax.xml.bind.Unmarshaller;
公共类EntityMarshalingUtils{
私有EntityMarshalingUtils(){}
@抑制警告(“未选中”)
公共静态T封送处理(c类,字符串xml)抛出JAXBEException{
T res;
如果(c==xml.getClass()){
res=(T)xml;
}
否则{
JAXBContext ctx=JAXBContext.newInstance(c);
解组器marshaller=ctx.createUnmarshaller();
res=(T)marshaller.unmarshal(新的StringReader(xml));
}
返回res;
}
@抑制警告(“未选中”)
公共静态字符串解组(类c,对象o)引发异常{
JAXBContext ctx=JAXBContext.newInstance(c);
Marshaller=ctx.createMarshaller();
StringWriter entityXml=新的StringWriter();
marshaller.marshall(o,entityXml);
String entityString=entityXml.toString();
返回entityString;
}
}
有人能帮我吗
String xml = EntityMarshallingUtils.unmarshal(org.eclipse.jetty.server.Response.class,**fields**);
System.out.println(xml);
package org.hp.qc.web.restapi.docexamples.docexamples.infrastructure;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.Marshaller;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
//import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
public class EntityMarshallingUtils {
private EntityMarshallingUtils() {}
@SuppressWarnings("unchecked")
public static <T> T marshal(Class<T> c, String xml) throws JAXBException {
T res;
if (c == xml.getClass()) {
res = (T) xml;
}
else {
JAXBContext ctx = JAXBContext.newInstance(c);
Unmarshaller marshaller = ctx.createUnmarshaller();
res = (T) marshaller.unmarshal(new StringReader(xml));
}
return res;
}
@SuppressWarnings("unchecked")
public static <T> String unmarshal(Class<T> c, Object o) throws Exception {
JAXBContext ctx = JAXBContext.newInstance(c);
Marshaller marshaller = ctx.createMarshaller();
StringWriter entityXml = new StringWriter();
marshaller.marshal(o, entityXml);
String entityString = entityXml.toString();
return entityString;
}
}