com.aliyuncs.v5.unmarshaller.XmlUnmashaller Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aliyun-java-sdk-core-v5 Show documentation
Show all versions of aliyun-java-sdk-core-v5 Show documentation
Aliyun Open API SDK for Java
Copyright (C) Alibaba Cloud Computing
All rights reserved.
版权所有 (C)阿里云计算有限公司
http://www.aliyun.com
The newest version!
package com.aliyuncs.v5.unmarshaller;
import com.aliyuncs.v5.AcsResponse;
import com.aliyuncs.v5.exceptions.ClientException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import java.io.StringReader;
public class XmlUnmashaller implements Unmarshaller {
@Override
public T unmarshal(Class clazz, String content) throws ClientException {
try {
JAXBContext jc = JAXBContext.newInstance(clazz);
javax.xml.bind.Unmarshaller unmarshaller = jc.createUnmarshaller();
return (T) unmarshaller.unmarshal(new StringReader(content));
} catch (JAXBException e) {
throw newUnmarshalException(clazz, content, e);
}
}
private ClientException newUnmarshalException(Class> clazz, String xmlContent, Exception e) {
return new ClientException("SDK.UnmarshalFailed",
"unmarshal response from xml content failed, clazz = " + clazz.getSimpleName() + ", origin response = " + xmlContent, e);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy