com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement Java Examples

The following examples show how to use com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultSchemaService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String getName( Class<?> klass )
{
    if ( AnnotationUtils.isAnnotationPresent( klass, JacksonXmlRootElement.class ) )
    {
        JacksonXmlRootElement rootElement = AnnotationUtils.getAnnotation( klass, JacksonXmlRootElement.class );

        if ( !StringUtils.isEmpty( rootElement.localName() ) )
        {
            return rootElement.localName();
        }
    }

    return CaseFormat.UPPER_CAMEL.to( CaseFormat.LOWER_CAMEL, klass.getSimpleName() );
}
 
Example #2
Source File: GsonJacksonBridgeSerializationTest.java    From immutables with Apache License 2.0 5 votes vote down vote up
@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());
}