为我的要求配置Jackson XMLMAPPER



我想配置Jackson XMLMAPPER,以便WriteValueAsString方法将提供以下要求:

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);     

谢谢madhu

我使用JAXB类,并删除了Jackson XMLMAPPER。 jaxbContext JC = JaxbContext.NewInstance(showinvoice.class); MARSHALLER M = JC.CREATEMARSHALLER();这提供了我正在寻找

的格式

谢谢madhu

最新更新