*/
public void testForceElementAsArray() throws Exception
{
final String XML = "<array><elem>value</elem><elem><property>123</property></elem><elem>1</elem></array>";
FromXmlParser xp = (FromXmlParser) _xmlFactory.createParser(new StringReader(XML));
// First: verify handling without forcing array handling:
assertToken(JsonToken.START_OBJECT, xp.nextToken()); // <array>
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <elem>
assertEquals("elem", xp.getCurrentName());
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
assertEquals("value", xp.getText());
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <elem>
assertEquals("elem", xp.getCurrentName());
assertToken(JsonToken.START_OBJECT, xp.nextToken()); // <property>
assertToken(JsonToken.FIELD_NAME, xp.nextToken());
assertEquals("property", xp.getCurrentName());
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
assertEquals("123", xp.getText());
assertToken(JsonToken.END_OBJECT, xp.nextToken()); // <object>
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <elem>
assertEquals("elem", xp.getCurrentName());
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
assertEquals("1", xp.getText());
assertToken(JsonToken.END_OBJECT, xp.nextToken()); // </array>
xp.close();
// And then with array handling:
xp = (FromXmlParser) _xmlFactory.createParser(new StringReader(XML));
assertTrue(xp.getParsingContext().inRoot());
assertToken(JsonToken.START_OBJECT, xp.nextToken()); // <array>
assertTrue(xp.getParsingContext().inObject()); // true until we do following:
// must request 'as-array' handling, which will "convert" current token:
assertTrue("Should 'convert' START_OBJECT to START_ARRAY", xp.isExpectedStartArrayToken());
assertToken(JsonToken.START_ARRAY, xp.getCurrentToken()); // <elem>
assertTrue(xp.getParsingContext().inArray());
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
assertTrue(xp.getParsingContext().inArray());
assertEquals("value", xp.getText());
assertToken(JsonToken.START_OBJECT, xp.nextToken()); // <property>
assertTrue(xp.getParsingContext().inObject());
assertToken(JsonToken.FIELD_NAME, xp.nextToken());
assertEquals("property", xp.getCurrentName());
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
assertEquals("123", xp.getText());
assertTrue(xp.getParsingContext().inObject());
assertToken(JsonToken.END_OBJECT, xp.nextToken()); // </property>
assertTrue(xp.getParsingContext().inArray());
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
assertTrue(xp.getParsingContext().inArray());
assertEquals("1", xp.getText());
assertToken(JsonToken.END_ARRAY, xp.nextToken()); // </array>
assertTrue(xp.getParsingContext().inRoot());
xp.close();
}