本文整理汇总了Java中de.odysseus.staxon.json.JsonXMLConfig类的典型用法代码示例。如果您正苦于以下问题:Java JsonXMLConfig类的具体用法?Java JsonXMLConfig怎么用?Java JsonXMLConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonXMLConfig类属于de.odysseus.staxon.json包,在下文中一共展示了JsonXMLConfig类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: xmlToJson
import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
void xmlToJson(InputStream xmlInput, OutputStream jsonOutput) throws XMLStreamException
{
JsonXMLConfig config = new JsonXMLConfigBuilder()
.autoArray(true)
.autoPrimitive(false)
.fieldPrefix("")
.contentField("content")
.build();
XMLEventReader reader = XMLInputFactory.newInstance().createXMLEventReader(xmlInput);
XMLEventWriter writer = new JsonXMLOutputFactory(config).createXMLEventWriter(jsonOutput);
writer.add(reader);
reader.close();
writer.close();
}
示例2: getDestination
import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
@Override
public Destination getDestination(WebApp webApp, HttpServletRequest req,
HttpServletResponse resp, OutputStream os, Properties outputProperties) throws XMLStreamException {
JsonXMLConfig config = new JsonXMLConfigBuilder()
.autoArray(autoArray)
.autoPrimitive(autoPrimitive)
.multiplePI(multiplePI)
.namespaceDeclarations(namespaceDeclarations)
.namespaceSeparator(namespaceSeparator)
.prettyPrint(prettyPrint)
.virtualRoot(virtualRoot)
.repairingNamespaces(repairingNamespaces)
.namespaceMappings(namespaceMappings)
.build();
XMLOutputFactory factory = new JsonXMLOutputFactory(config);
return new XMLStreamWriterDestination(factory.createXMLStreamWriter(os, outputProperties.getProperty("encoding", "UTF-8")));
}
示例3: call
import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
StringWriter sw = new StringWriter();
JsonXMLConfig config = new JsonXMLConfigBuilder().
prettyPrint(true).
build();
XMLOutputFactory jFactory = new JsonXMLOutputFactory(config);
TransformerFactory tFactory = new TransformerFactoryImpl();
try {
SequenceIterator iter = arguments[0].iterate();
Item item;
while ((item = iter.next()) != null) {
if (item instanceof NodeInfo) {
Transformer transformer = tFactory.newTransformer();
XMLStreamWriter xsw = jFactory.createXMLStreamWriter(sw);
transformer.transform((NodeInfo) item, new StAXResult(xsw));
} else {
sw.append(item.getStringValue());
}
}
} catch (Exception e) {
throw new XPathException("Error serializing sequence to JSON", e);
}
return StringValue.makeStringValue(sw.toString());
}
示例4: convertXmlToJson
import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
/**
* Converts xml to json.
*
* @param xml xml as byte array.
* @return json as byte array.
*/
public byte[] convertXmlToJson(byte[] xml) {
JsonXMLConfig config = new JsonXMLConfigBuilder()
.prettyPrint(true)
.autoArray(true)
.autoPrimitive(true)
.build();
XMLInputFactory reader = XMLInputFactory.newInstance();
JsonXMLOutputFactory writer = new JsonXMLOutputFactory(config);
return convert(reader, writer, xml);
}
示例5: convertJsonToXml
import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
/**
* Converts json to xml.
*
* @param json json as byte array.
* @return xml as byte array.
*/
public byte[] convertJsonToXml(byte[] json) {
JsonXMLConfig config = new JsonXMLConfigBuilder()
.prettyPrint(true)
.multiplePI(false)
.build();
XMLInputFactory reader = new JsonXMLInputFactory(config);
XMLOutputFactory writer = XMLOutputFactory.newInstance();
return convert(reader, writer, json);
}
示例6: xmlQuizzToJson
import de.odysseus.staxon.json.JsonXMLConfig; //导入依赖的package包/类
/**
* . Lit le fichier de quizz XML xmlInput, ecrit le test convertit en JSON
* dans le fichier jsonOutput
*
* @param xmlInput
* Ficher de Quizz XML
* @param jsonOutput
* Fichier de sortie JSON
* @throws IOException
* exception entrée/sortie
* @throws FactoryConfigurationError
* Erreur de configurations
* @throws XMLStreamException
* exception de flux XML
*/
public static void xmlQuizzToJson(final File xmlInput, final File jsonOutput)
throws IOException, XMLStreamException, FactoryConfigurationError {
InputStream is = new FileInputStream(xmlInput);
OutputStream os = new FileOutputStream(jsonOutput);
Reader r = new InputStreamReader(is, "UTF-8");
Writer w = new OutputStreamWriter(os, "UTF-8");
JsonXMLConfig config = new JsonXMLConfigBuilder().autoArray(true)
.autoPrimitive(true).prettyPrint(true).build();
try {
/*
* Create reader (XML).
*/
XMLEventReader reader = XMLInputFactory.newInstance()
.createXMLEventReader(r);
/*
* Create writer (JSON).
*/
XMLEventWriter writer = new JsonXMLOutputFactory(config)
.createXMLEventWriter(w);
/*
* Copy events from reader to writer.
*/
writer.add(reader);
/*
* Close reader/writer.
*/
reader.close();
writer.close();
} finally {
/*
* As per StAX specification, XMLEventReader/Writer.close() doesn't
* close the underlying stream.
*/
r.close();
w.close();
os.close();
is.close();
}
}