java jaxb序列化 空值_java-如何告诉JAXB在运行时要序列化哪些字段...

注意:我是EclipseLink JAXB (MOXy)主管,并且是JAXB (JSR-222)专家组的成员.

在EclipseLink 2.5(在此处获取:http://www.eclipse.org/eclipselink/downloads/milestones.php)中,我们向MOXy JAXB添加了一个称为“对象图”的新功能.对象图允许以编程方式或通过元数据选择要封送/取消封送的属性的子集.下面是创建对象图以从“客户”,“地址”和“电话号码”模型中获取数据子集的示例.

// Create the Object Graph

ObjectGraph contactInfo = JAXBHelper.getJAXBContext(jc).createObjectGraph(Customer.class);

contactInfo.addAttributeNodes("name");

Subgraph location = contactInfo.addSubgraph("billingAddress");

location.addAttributeNodes("city", "province");

Subgraph simple = contactInfo.addSubgraph("phoneNumbers");

simple.addAttributeNodes("value");

// Output XML - Based on Object Graph

marshaller.setProperty(MarshallerProperties.OBJECT_GRAPH, contactInfo);

marshaller.marshal(customer, System.out);

欲获得更多信息


版权声明:本文为weixin_31129821原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。