本文整理匯總了Java中com.thoughtworks.xstream.XStream.autodetectAnnotations方法的典型用法代碼示例。如果您正苦於以下問題:Java XStream.autodetectAnnotations方法的具體用法?Java XStream.autodetectAnnotations怎麽用?Java XStream.autodetectAnnotations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.thoughtworks.xstream.XStream
的用法示例。
在下文中一共展示了XStream.autodetectAnnotations方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadXML
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
public static SPStoryWorldData loadXML(File xmlFile) throws FileNotFoundException {
FileReader reader = new FileReader(xmlFile);
XStream xstream = new XStream(new DomDriver());
xstream.autodetectAnnotations(true);
xstream.alias(SPStoryWorldData.class.getAnnotation(XStreamAlias.class).value(), SPStoryWorldData.class);
Object obj = xstream.fromXML(reader);
try {
reader.close();
} catch (IOException e) {
}
if (!(obj instanceof SPStoryWorldData)) throw new RuntimeException("file " + xmlFile.getAbsolutePath() + " doesn't contain a xml with SPStoryWorldData");
SPStoryWorldData data = (SPStoryWorldData) obj;
data.file = xmlFile.getAbsolutePath();
return data;
}
示例2: createCloner
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
@Override
public <T> Function<T, T> createCloner(ClassLoader classLoader)
{
final XStream xstream = new XStream() {
@Override
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new HibernateMapper(next);
}
};
xstream.setClassLoader(classLoader);
xstream.autodetectAnnotations(true);
xstream.registerConverter(new HibernateProxyConverter());
xstream.registerConverter(new HibernatePersistentCollectionConverter(xstream.getMapper()));
xstream.registerConverter(new HibernatePersistentMapConverter(xstream.getMapper()));
xstream.registerConverter(new HibernatePersistentSortedMapConverter(xstream.getMapper()));
xstream.registerConverter(new HibernatePersistentSortedSetConverter(xstream.getMapper()));
return t -> (T) xstream.fromXML(xstream.toXML(t));
}
示例3: fromObjectToXML
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
/**
* From object to xml.
*
* @param object
* the object
* @return the string
*/
public void fromObjectToXML(Serializable object,ByteArrayOutputStream outputStream) {
String str = "<!-- It is recommended to avoid changes to xml data -->\n\n";
XStream xs = new XStream();
xs.autodetectAnnotations(true);
try {
xs.toXML(object, outputStream);
logger.debug( "Sucessfully converted XML from JAVA Object");
} catch (Exception e) {
logger.error("Failed to convert from Object to XML", e);
}
XMLUtil.unformatXMLString(outputStream);
}
示例4: toPojo
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
public static GerarNFSeResposta toPojo(String xml) {
XStream xstream = new XStream();
xstream.setMode(XStream.NO_REFERENCES);
xstream.autodetectAnnotations(true);
xstream.ignoreUnknownElements();
xstream.alias("GerarNfseResposta", GerarNFSeResposta.class);
xstream.alias("Nfse", NFSe.class);
GerarNFSeResposta gerarNfseResposta = (GerarNFSeResposta) xstream.fromXML(xml);
return gerarNfseResposta;
}
示例5: converterParaXml
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
public String converterParaXml() {
String XML_HEADER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
XStream xstream = new XStream();
xstream.setMode(XStream.NO_REFERENCES);
xstream.autodetectAnnotations(true);
return XML_HEADER + xstream.toXML(this);
}
示例6: toPojo
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
public static ConsultarLoteRpsResposta toPojo(String xml) {
XStream xstream = new XStream();
xstream.setMode(XStream.NO_REFERENCES);
xstream.autodetectAnnotations(true);
xstream.ignoreUnknownElements();
xstream.alias("ConsultarLoteRpsResposta", ConsultarLoteRpsResposta.class);
xstream.alias("Nfse", Nfse.class);
ConsultarLoteRpsResposta gerarNfseResposta = (ConsultarLoteRpsResposta) xstream.fromXML(xml);
return gerarNfseResposta;
}
示例7: toPojo
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
public static EnviarLoteRpsResposta toPojo(String xml) {
XStream xstream = new XStream();
xstream.setMode(XStream.NO_REFERENCES);
xstream.autodetectAnnotations(true);
xstream.ignoreUnknownElements();
xstream.alias("EnviarLoteRpsResposta", EnviarLoteRpsResposta.class);
EnviarLoteRpsResposta enviarLoteRpsResposta = (EnviarLoteRpsResposta) xstream.fromXML(xml);
return enviarLoteRpsResposta;
}
示例8: toPojo
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
public static CompNFSe toPojo(String xml) {
XStream xstream = new XStream();
xstream.setMode(XStream.NO_REFERENCES);
xstream.autodetectAnnotations(true);
xstream.ignoreUnknownElements();
xstream.alias("CompNfse", CompNFSe.class);
xstream.alias("Nfse", NFSe.class);
CompNFSe compNfse = (CompNFSe) xstream.fromXML(xml);
return compNfse;
}
示例9: customizeXstream
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
@Override
public void customizeXstream(XStream xstream) {
xstream.registerConverter(new ShrimpSpeciesNodeXMLConverter());
xstream.alias("ShrimpSpeciesNode", ShrimpSpeciesNode.class);
xstream.registerConverter(new SquidSpeciesModelXMLConverter());
xstream.alias("SquidSpeciesModel", SquidSpeciesModel.class);
xstream.registerConverter(new ConstantNodeXMLConverter());
xstream.alias("ConstantNode", ConstantNode.class);
xstream.registerConverter(new VariableNodeForSummaryXMLConverter());
xstream.alias("VariableNodeForSummary", VariableNodeForSummary.class);
xstream.alias("VariableNodeForPerSpotTaskExpressions", VariableNodeForPerSpotTaskExpressions.class);
xstream.alias("VariableNodeForIsotopicRatios", VariableNodeForIsotopicRatios.class);
xstream.registerConverter(new OperationXMLConverter());
xstream.alias("Operation", Operation.class);
xstream.registerConverter(new FunctionXMLConverter());
xstream.alias("Operation", Function.class);
xstream.alias("Operation", OperationOrFunctionInterface.class);
xstream.registerConverter(new ExpressionTreeXMLConverter());
xstream.alias("ExpressionTree", ExpressionTree.class);
xstream.alias("ExpressionTree", ExpressionTreeInterface.class);
xstream.registerConverter(new ExpressionXMLConverter());
xstream.alias("Expression", Expression.class);
// Note: http://cristian.sulea.net/blog.php?p=2014-11-12-xstream-object-references
xstream.setMode(XStream.NO_REFERENCES);
xstream.autodetectAnnotations(true);
}
示例10: customizeXstream
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
/**
*
* @param xstream
*/
@Override
public void customizeXstream(XStream xstream) {
xstream.registerConverter(new ShrimpSpeciesNodeXMLConverter());
xstream.alias("ShrimpSpeciesNode", ShrimpSpeciesNode.class);
xstream.registerConverter(new SquidSpeciesModelXMLConverter());
xstream.alias("SquidSpeciesModel", SquidSpeciesModel.class);
xstream.registerConverter(new ConstantNodeXMLConverter());
xstream.alias("ConstantNode", ConstantNode.class);
xstream.registerConverter(new VariableNodeForSummaryXMLConverter());
xstream.alias("VariableNodeForSummary", VariableNodeForSummary.class);
xstream.alias("VariableNodeForPerSpotTaskExpressions", VariableNodeForPerSpotTaskExpressions.class);
xstream.alias("VariableNodeForIsotopicRatios", VariableNodeForIsotopicRatios.class);
xstream.registerConverter(new OperationXMLConverter());
xstream.alias("Operation", Operation.class);
xstream.registerConverter(new FunctionXMLConverter());
xstream.alias("Operation", Function.class);
xstream.alias("Operation", OperationOrFunctionInterface.class);
xstream.registerConverter(new ExpressionTreeXMLConverter());
xstream.alias("ExpressionTree", ExpressionTree.class);
xstream.alias("ExpressionTree", ExpressionTreeInterface.class);
// Note: http://cristian.sulea.net/blog.php?p=2014-11-12-xstream-object-references
xstream.setMode(XStream.NO_REFERENCES);
xstream.autodetectAnnotations(true);
}
示例11: replyToXml
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
/**
* 將回複消息對象轉換成xml字符串
*
* @param reply 回複消息對象
* @return 返回符合微信接口的xml字符串
*/
public String replyToXml(WeChatReply reply) {
XStream xstream = new XStream(new XppDriver() {
public HierarchicalStreamWriter createWriter(Writer out) {
return new PrettyPrintWriter(out) {
// 對所有xml節點的轉換都增加CDATA標記
boolean cdata = true;
@SuppressWarnings("unchecked")
public void startNode(String name, Class clazz) {
super.startNode(name, clazz);
}
protected void writeText(QuickWriter writer, String text) {
if (cdata) {
writer.write("<![CDATA[");
writer.write(text);
writer.write("]]>");
} else {
writer.write(text);
}
}
};
}
});
String type = reply.getMsgType();
if (WeChatReply.TEXT.equals(type)) {
xstream.omitField(WeChatReply.class, "articles");
xstream.omitField(WeChatReply.class, "articleCount");
xstream.omitField(WeChatReply.class, "musicUrl");
xstream.omitField(WeChatReply.class, "hQMusicUrl");
} else if (WeChatReply.MUSIC.equals(type)) {
xstream.omitField(WeChatReply.class, "articles");
xstream.omitField(WeChatReply.class, "articleCount");
xstream.omitField(WeChatReply.class, "content");
} else if (WeChatReply.NEWS.equals(type)) {
xstream.omitField(WeChatReply.class, "content");
xstream.omitField(WeChatReply.class, "musicUrl");
xstream.omitField(WeChatReply.class, "hQMusicUrl");
}
xstream.autodetectAnnotations(true);
xstream.alias("xml", reply.getClass());
xstream.alias("item", new Article().getClass());
return xstream.toXML(reply);
}
示例12: xmlStringToBean
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
/**
* 把XML轉成對象
*
* @param xmlStr
* @return Object
*/
@SuppressWarnings("unchecked")
public static <T> T xmlStringToBean(String xmlStr, Class<T> cls) {
XStream xstream = new XStream(new DomDriver());
xstream.processAnnotations(cls);
xstream.autodetectAnnotations(true);
return (T) xstream.fromXML(xmlStr);
}
示例13: init
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
protected XStream init(BDLParserXMLConfig config) {
XStream xstream = new XStream(new DomDriver());
xstream.autodetectAnnotations(true);
config.configXStream(xstream);
return xstream;
}
示例14: generateUiXml
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
/**
* Creates the job file based for the container object.
*
* @param container
* @param jobFile
* @param parameterFile
*/
private void generateUiXml(Container container, IFile jobFile, IFile parameterFile) {
LOGGER.debug("Generating UI-XML");
ByteArrayOutputStream out = new ByteArrayOutputStream();
String jobXmlData = null;
IPath iPath = new Path(jobFile.getFullPath().toString());
try {
XStream xs = new XStream();
xs.autodetectAnnotations(true);
xs.toXML(container,out);
XMLUtil.unformatXMLString(out);
if (jobFile.exists()) {
showMessageBox(jobFile, out, jobFile.getName() + " already exists.Do you want to replace it?");
} else {
jobFile.create(new ByteArrayInputStream(out.toByteArray()), true, null);
}
} catch (CoreException e) {
LOGGER.error("Exception occurred while creating UI-XML", e);
} finally {
componentRepo.flushRepository();
try {
out.close();
} catch (IOException ioe) {
LOGGER.error("IOException occurred while closing output stream", ioe);
}
}
ImportedJobsRepository.INSTANCE.addImportedJobName(jobFile);
jobXmlData = getStringValueFromXMLFile(iPath);
storeParameterData(parameterFile, jobXmlData);
}
示例15: generateSubjobUiXml
import com.thoughtworks.xstream.XStream; //導入方法依賴的package包/類
private void generateSubjobUiXml(Container container, File file, IFile parameterFile) {
LOGGER.debug("Generating UI-XML");
XStream xs = new XStream();
xs.autodetectAnnotations(true);
try(FileOutputStream fileOutputStream = new FileOutputStream(file.getPath())) {
xs.toXML(container, fileOutputStream);
IPath iPath = new Path(file.getPath());
storeParameterData(parameterFile, getStringValueFromXMLFile(iPath));
} catch (IOException ioException) {
LOGGER.error("Exception occurred while creating UI-XML", ioException);
} finally {
componentRepo.flushRepository();
}
}