Domanda

In the Link below is perfectly explained how to write objects into an XML-File. My Question ist, how can I beware some Attributes to be written into the XML-File?

This is the Link I mean

For Example:

public class Human{

    private String name;
    private int age;
    private DateMinutesHours birthday;

    public Human(nam, ag, bir){

        this.name = nam;
        this.age= ag;
        this.birthday= bir;
    }

    @XmlElement( name = "lastname")
    public getName(){
        return this.name;
    }

    @NotAnXmlElement << Do something like this exist? 
    public getAge(){
        return this.age;
    }
}
È stato utile?

Soluzione

Exclude Less Than Half of the Properties

You can use the @XmlTransient annotation on the property to exclude it from being written to XML.

Exclude More Than Half of the Properties

If you are excluding a lot of properties then you can specify @XmlAccessorType (XmlAcceessType.NONE) on the class. This means that only things you explicitly annotate will be converted to/from XML.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top