2016-06-22 2 views
0

Я хочу настроить Джексон XmlMapper так, что метод writeValueAsString обеспечит следующие требования:Настройка Джексон XmlMapper для моих требований

1. Eliminate null/empty tags: Ex: <carrierDocumentId/> 
2. Tags to display its namespace: Ex: <documentId> to displayed as 
    <ims:documentId> 
3. Tags to use the upper case letter as provided in 
    @XmlElement(name = "DocumentId") 
4. List objects to not to include a wrapper tag: 
<documentId><documentId>12345</documentId></documentId> 
5. Attribute tags to display as attribute instead of element: 
    Ex: <id><value>6802554587</value><idOrigin>Invoice</idOrigin></id> 
    to be displayed as <id idOrigin="Invoice">6802554587</id> 

Я попытался с различными комбинациями:

//JaxbAnnotationModule module = new JaxbAnnotationModule(); 
     //AnnotationIntrospector introspector = new 
     JaxbAnnotationIntrospector(serializeMapper.getTypeFactory()); 
     //serializeMapper.setAnnotationIntrospector(introspector); 
     //serializeMapper.registerModule(module);  

    //serializeMapper.configure(SerializationFeature.WRAP_ROOT_VALUE,false);  

    //serializeMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); 

    //serializeMapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME); 

    //serializeMapper.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); 

     //JacksonXmlModule module = new JacksonXmlModule(); 
     JaxbAnnotationModule module = new JaxbAnnotationModule(); 
     // and then configure, for example: 
     //module.setDefaultUseWrapper(false); 
     serializeMapper = new XmlMapper(); 
     AnnotationIntrospector introspector = new 
     JaxbAnnotationIntrospector(serializeMapper.getTypeFactory()); 
     serializeMapper.setAnnotationIntrospector(introspector); 
     serializeMapper.registerModule(module);  

благодаря Мадх

ответ

0

Я использовал классы JAXB следующим образом и удалил jsonson XmlMapper. JAXBContext jc = JAXBContext.newInstance (ShowInvoice.class); Marshaller m = jc.createMarshaller(); Это при условии, что я форматирование искал

Благодарности Мадху

Смежные вопросы