What if I do not want some variables to be marshalled into XML file?

前端 未结 1 999
轻奢々
轻奢々 2021-01-23 00:15
package jaxb.classes;

import javax.xml.bind.annotation.*;

@XmlAccessorType(XmlAccessType.FIELD)
public class Task {
    @XmlElement(name=\"input\")
    private String          


        
1条回答
  •  囚心锁ツ
    2021-01-23 00:29

    There are a couple of ways to support this use case:

    Option #1 - @XmlTransient

    You can use the @XmlTransient annotation to prevent a field/property from being marshalled or unmarshalled.

    Option #2 - @XmlAccessorType(XmlAccessType.NONE)

    You can annotated the class with @XmlAccessorType(XmlAccessType.NONE) so that only annotated fields/properties will be marshalled/unmarshalled.

    For More Information

    • http://blog.bdoughan.com/2012/04/jaxb-and-unmapped-properties.html

    0 讨论(0)
提交回复
热议问题