update xmlrootelement annotation

This commit is contained in:
jinyu
2015-06-04 00:16:37 +08:00
parent 19c613f26b
commit dce67fcc80
38 changed files with 151 additions and 25 deletions
@@ -164,7 +164,9 @@ public class SimpleHttpClient implements HttpClient {
if (os != null) {
os.close();
}
is.close();
if (is != null) {
is.close();
}
}
}
HttpResponse response = new HttpResponse();
@@ -5,6 +5,7 @@ import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.alibaba.fastjson.annotation.JSONField;
@@ -17,6 +18,7 @@ import com.alibaba.fastjson.annotation.JSONField;
* @since JDK 1.7
* @see
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlResult implements Serializable {
@@ -77,14 +77,16 @@ public final class XmlStream {
Source source = new StreamSource(content);
XmlRootElement rootElement = clazz
.getAnnotation(XmlRootElement.class);
if (rootElement == null) {
if (rootElement == null || rootElement.name().equals(
XmlRootElement.class.getMethod("name")
.getDefaultValue().toString())) {
JAXBElement<T> jaxbElement = unmarshaller.unmarshal(source,
clazz);
return jaxbElement.getValue();
} else {
return (T) unmarshaller.unmarshal(source);
}
} catch (JAXBException e) {
} catch (Exception e) {
throw new IllegalArgumentException(e);
} finally {
if (content != null) {
@@ -253,7 +255,10 @@ public final class XmlStream {
try {
XmlRootElement rootElement = clazz
.getAnnotation(XmlRootElement.class);
if (rootElement == null) {
if (rootElement == null
|| rootElement.name().equals(
XmlRootElement.class.getMethod("name")
.getDefaultValue().toString())) {
marshaller.marshal(new JAXBElement<T>(new QName(
ROOT_ELEMENT_XML), clazz, t), os);
} else {