本文整理汇总了Java中org.codehaus.jettison.AbstractXMLStreamWriter.writeCharacters方法的典型用法代码示例。如果您正苦于以下问题:Java AbstractXMLStreamWriter.writeCharacters方法的具体用法?Java AbstractXMLStreamWriter.writeCharacters怎么用?Java AbstractXMLStreamWriter.writeCharacters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.jettison.AbstractXMLStreamWriter
的用法示例。
在下文中一共展示了AbstractXMLStreamWriter.writeCharacters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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());
}
示例3: 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());
}
示例4: testTwoChildrenWithSameName
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testTwoChildrenWithSameName() throws Exception {
StringWriter strWriter = new StringWriter();
AbstractXMLStreamWriter w = new BadgerFishXMLStreamWriter(strWriter);
w.writeStartDocument();
w.writeStartElement("alice");
w.writeStartElement("bob");
w.writeCharacters("charlie");
w.writeEndElement();
w.writeStartElement("bob");
w.writeCharacters("david");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertJSONEquals("{\"alice\":{\"bob\":[{\"$\":\"charlie\"},{\"$\":\"david\"}]}}",
strWriter.toString());
}
示例5: 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());
}
示例6: 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());
}
示例7: 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());
}
示例8: testTwoChildren
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testTwoChildren() throws Exception {
StringWriter strWriter = new StringWriter();
AbstractXMLStreamWriter w = new BadgerFishXMLStreamWriter(strWriter);
w.writeStartDocument();
w.writeStartElement("alice");
w.writeStartElement("bob");
w.writeCharacters("charlie");
w.writeEndElement();
w.writeStartElement("david");
w.writeCharacters("edgar");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertJSONEquals("{\"alice\":{\"bob\":{\"$\":\"charlie\"},"+
"\"david\":{\"$\":\"edgar\"}}}", strWriter.toString());
}
示例9: testAttributeAndText
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testAttributeAndText() throws Exception {
StringWriter strWriter = new StringWriter();
AbstractXMLStreamWriter w = new BadgerFishXMLStreamWriter(strWriter);
w.writeStartDocument();
w.writeStartElement("alice");
w.writeAttribute("charlie", "david");
w.writeCharacters("bob");
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertJSONEquals("{\"alice\":{\"@charlie\":\"david\",\"$\":\"bob\"}}",
strWriter.toString());
}
示例10: testBootstrapConverter
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testBootstrapConverter() throws Exception {
Configuration cfg = new Configuration();
cfg.setTypeConverter(new ReplacementTypeConverter());
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention(cfg);
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("subchild1");
w.writeCharacters("Not success");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
String expected = "{\"root\":{\"subchild1\":\"success\"}}";
String actual = strWriter.toString();
assertEquals(expected, actual);
}
示例11: testComplexElements
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testComplexElements() throws Exception {
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention();
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("", "a", "");
w.writeStartElement("", "o", "");
w.writeAttribute("class", "string");
w.writeCharacters("1");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"a\":{\"o\":{\"@class\":\"string\",\"$\":\"1\"}}}", strWriter.toString());
}
示例12: testSingleArrayElementIgnore
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testSingleArrayElementIgnore() throws Exception {
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention();
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("", "array-a", "");
w.writeStartElement("", "a", "");
w.writeStartElement("", "n", "");
w.writeCharacters("1");
w.writeEndElement();
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"array-a\":{\"a\":{\"n\":1}}}", strWriter.toString());
}
示例13: testTwoChildrenWithSubChildWithText
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testTwoChildrenWithSubChildWithText() throws Exception {
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention();
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("child1");
w.writeStartElement("subchild1");
w.writeCharacters("test");
w.writeEndElement();
w.writeStartElement("subchild2");
w.writeCharacters("test");
w.writeEndElement();
w.writeEndElement();
w.writeStartElement("child2");
w.writeStartElement("subchild");
w.writeCharacters("test");
w.writeEndElement();
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{" +
"\"child1\":{\"subchild1\":\"test\",\"subchild2\":\"test\"}," +
"\"child2\":{\"subchild\":\"test\"}}}", strWriter.toString());
}
示例14: testPrimitiveUnenforcedInteger
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
/**
* issue 61
* @see DefaultTypeConverterEnforcedIntegerTest
*/
public void testPrimitiveUnenforcedInteger() throws Exception {
assertFalse( DefaultConverter.ENFORCE_32BIT_INTEGER );
StringWriter strWriter = new StringWriter();
MappedNamespaceConvention con = new MappedNamespaceConvention();
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
w.writeStartDocument();
w.writeStartElement("root");
w.writeStartElement("subchild1");
w.writeCharacters(Long.MAX_VALUE + "");
w.writeEndElement();
w.writeStartElement("subchild1");
w.writeCharacters(Long.MIN_VALUE + "");
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
String expected = "{\"root\":{\"subchild1\":[" + Long.MAX_VALUE + "," + Long.MIN_VALUE + "]}}";
String actual = strWriter.toString();
assertEquals(expected, actual);
}
示例15: testArrayOfChildren
import org.codehaus.jettison.AbstractXMLStreamWriter; //导入方法依赖的package包/类
public void testArrayOfChildren() 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("first");
w.writeEndElement();
w.writeStartElement("child");
w.writeCharacters("second");
w.writeEndElement();
w.writeStartElement("child");
w.writeCharacters("third");
w.writeEndElement();
w.writeEndElement();
w.writeStartElement("other");
w.writeCharacters("test");
w.writeEndElement();
w.writeEndDocument();
w.close();
strWriter.close();
assertEquals("{\"root\":{\"child\":[\"first\",\"second\",\"third\"]},\"other\":\"test\"}", strWriter.toString());
}