// root name is special, need to be fed first:
gen.setNextName(new QName("root"));
gen.writeStartObject();
gen.writeFieldName("elem");
gen.writeString("value");
gen.writeEndObject();
gen.close();
String xml = out.toString();
// one more thing: remove that annoying 'xmlns' decl, if it's there:
xml = removeSjsxpNamespace(xml);
assertEquals("<root><elem>value</elem></root>", xml);