本文整理汇总了Java中org.codehaus.jettison.AbstractXMLStreamWriter类的典型用法代码示例。如果您正苦于以下问题:Java AbstractXMLStreamWriter类的具体用法?Java AbstractXMLStreamWriter怎么用?Java AbstractXMLStreamWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractXMLStreamWriter类属于org.codehaus.jettison包,在下文中一共展示了AbstractXMLStreamWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startNode
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
@Override
public void startNode(final String name, final Class<?> clazz) {
final XMLStreamWriter out = getXMLStreamWriter();
if (clazz != null && out instanceof AbstractXMLStreamWriter) {
if (Collection.class.isAssignableFrom(clazz) || Map.class.isAssignableFrom(clazz) || clazz.isArray()) {
final QName qname = getQNameMap().getQName(encodeNode(name));
final String prefix = qname.getPrefix();
final String uri = qname.getNamespaceURI();
final String key = convention.createKey(prefix, uri, qname.getLocalPart());
if (!((AbstractXMLStreamWriter)out).getSerializedAsArrays().contains(key)) {
// Typo is in the API of Jettison ...
((AbstractXMLStreamWriter)out).seriliazeAsArray(key);
}
}
}
startNode(name);
}
示例2: testChild
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testChild() throws Exception {
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention();
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("child");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"child\":\"\"}}", strWriter.toString());
}
示例3: testChildDropElement
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testChildDropElement() throws Exception {
StringWriter strWriter = new StringWriter();
Configuration c = new Configuration();
c.setDropRootElement(true);
MappedNamespaceConvention con = new MappedNamespaceConvention(c);
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("child");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"child\":\"\"}", strWriter.toString());
}
示例4: testChildDropElement2
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testChildDropElement2() throws Exception {
StringWriter strWriter = new StringWriter();
Configuration c = new Configuration();
c.setDropRootElement(true);
MappedNamespaceConvention con = new MappedNamespaceConvention(c);
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("root2");
w.writeStartElement("child");
w.writeEndElement();
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root2\":{\"child\":\"\"}}", strWriter.toString());
}
示例5: testChildDropElement3
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testChildDropElement3() throws Exception {
StringWriter strWriter = new StringWriter();
Configuration c = new Configuration();
List<String> ignoredElements = new LinkedList<String>();
ignoredElements.add("root");
ignoredElements.add("root2");
c.setIgnoredElements(ignoredElements);
MappedNamespaceConvention con = new MappedNamespaceConvention(c);
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("root2");
w.writeStartElement("child");
w.writeEndElement();
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"child\":\"\"}", strWriter.toString());
}
示例6: testChildDropElement4
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testChildDropElement4() throws Exception {
StringWriter strWriter = new StringWriter();
Configuration c = new Configuration();
List<String> ignoredElements = new LinkedList<String>();
ignoredElements.add("child");
c.setIgnoredElements(ignoredElements);
MappedNamespaceConvention con = new MappedNamespaceConvention(c);
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("child");
w.writeEndElement();
w.writeStartElement("child2");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"child2\":\"\"}}", strWriter.toString());
}
示例7: testText
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testText() throws Exception {
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention();
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("child");
w.writeCharacters("test");
w.writeCharacters("test");
w.writeCharacters("test".toCharArray(), 0, 4);
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"child\":\"testtesttest\"}}", strWriter.toString());
}
示例8: testTextEscapeForwardSlash
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testTextEscapeForwardSlash() throws Exception {
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention();
con.setEscapeForwardSlashAlways(true);
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("child");
w.writeCharacters("http://localhost:8080/json");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"child\":\"http:\\/\\/localhost:8080\\/json\"}}", strWriter.toString());
}
示例9: testTextForwardSlash
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testTextForwardSlash() throws Exception {
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention();
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("child");
w.writeCharacters("http://localhost:8080/json");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"child\":\"http://localhost:8080/json\"}}", strWriter.toString());
}
示例10: testTextForwardSlashWithLeftAngle
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testTextForwardSlashWithLeftAngle() throws Exception {
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention();
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("child");
w.writeCharacters("</abc>");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"child\":\"<\\/abc>\"}}", strWriter.toString());
}
示例11: testTextForwardSlashFirstChar
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testTextForwardSlashFirstChar() throws Exception {
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention();
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("child");
w.writeCharacters("/abc");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"child\":\"/abc\"}}", strWriter.toString());
}
示例12: testTextNullAsString
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testTextNullAsString() throws Exception {
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention();
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("child");
w.writeCharacters(null);
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"child\":\"null\"}}", strWriter.toString());
}
示例13: testTextNullAsNull
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testTextNullAsNull() throws Exception {
StringWriter strWriter = new StringWriter();
Configuration c = new Configuration();
c.setWriteNullAsString(false);
MappedNamespaceConvention con = new MappedNamespaceConvention(c);
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("child");
w.writeCharacters(null);
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"child\":null}}", strWriter.toString());
}
示例14: testAttributes
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testAttributes() throws Exception {
StringWriter strWriter = new StringWriter();
Map xtoj = new HashMap();
xtoj.put("http://foo/", "foo");
MappedNamespaceConvention con = new MappedNamespaceConvention(new Configuration(xtoj));
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeAttribute("att", "attvalue");
w.writeAttribute("http://foo/", "att2", "attvalue");
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"@att\":\"attvalue\",\"@foo.att2\":\"attvalue\"}}", strWriter.toString());
}
示例15: testIntAttribute
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入依赖的package包/类
public void testIntAttribute() throws Exception {
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention(new Configuration());
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeAttribute("att", "123");
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"@att\":123}}", strWriter.toString());
}