use of com.fasterxml.jackson.dataformat.xml.XmlFactory in project immutables by immutables.
the class GsonJacksonBridgeSerializationTest method xmlFactoryTest.
@Test
public void xmlFactoryTest() throws IOException {
TestObject value = createTestObject();
XmlFactory factory = new XmlFactory();
Class<TestObject> clazz = TestObject.class;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ToXmlGenerator g = factory.createGenerator(outputStream);
g.setNextName(QName.valueOf(clazz.getAnnotation(JacksonXmlRootElement.class).localName()));
JsonGeneratorWriter generatorWriter = new JsonGeneratorWriter(g);
gson.toJson(value, clazz, generatorWriter);
generatorWriter.flush();
TestObject value2 = testXmlReading(factory, clazz, outputStream);
Assert.assertEquals(value2.toString(), value.toString());
}
use of com.fasterxml.jackson.dataformat.xml.XmlFactory in project dhis2-core by dhis2.
the class CustomLastUpdatedUserSerializerTest method serializeXml.
@Test
void serializeXml() throws Exception {
Writer jsonWriter = new StringWriter();
ToXmlGenerator jsonGenerator = new XmlFactory().createGenerator(jsonWriter);
SerializerProvider serializerProvider = new ObjectMapper().getSerializerProvider();
jsonGenerator.setNextName(new QName("urn:test", "lastUpdatedBy"));
new CustomLastUpdatedUserSerializer().serialize(user, jsonGenerator, serializerProvider);
jsonGenerator.flush();
assertEquals("<wstxns1:lastUpdatedBy xmlns:wstxns1=\"urn:test\" id=\"jshfdkd323\" name=\"Peter Brown\"/>", jsonWriter.toString());
}
use of com.fasterxml.jackson.dataformat.xml.XmlFactory in project dhis2-core by dhis2.
the class StAXNodeSerializer method startSerialize.
@Override
protected void startSerialize(RootNode rootNode, OutputStream outputStream) throws Exception {
writer = xmlFactory.createXMLStreamWriter(outputStream);
generator = (new XmlFactory()).createGenerator(writer);
generator.setCodec(new XmlMapper());
writer.setDefaultNamespace(rootNode.getDefaultNamespace());
}
Aggregations