package jaxb.classes;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
public class Task {
@XmlElement(name="input")
private String input; // String representing the input file
@XmlElement(name="output")
private String output; // String representing the output file
@XmlElement(name="format")
private Format format; // a jaxb.classes.Format representing the format of conversion
@XmlElement(name="taskID")
private long taskID; // a unique ID for each task.
@XmlElement(name="isReady")
public boolean isReady; // boolean value representing whether the task is ready for conversion
public boolean isChanging; // boolean representing if the user is changing the task DO NOT MARSHALL
public boolean isExecuting; // boolean representing whether the task is being executed DO NOT MARSHALL
public long getTaskID(){
return taskID;
}
public String getInput(){
return input;
}
public String getOutput(){
return output;
}
public Format getFormat(){
return format;
}
public void setOutput(String out){
output = out;
}
public void setFormat(Format f){
format = f;
}
}
因此,这是一个表示转换待处理任务的类。这将转换为包含已保存数据的XML
但是,我不希望isChanging
,isExecuting
成为XML。当他们被回读时,我希望他们是false
。
我该怎么做?
答案 0 :(得分:2)
有几种方法可以支持这种用例:
选项#1 - @XmlTransient
您可以使用@XmlTransient
注释来阻止字段/属性被编组或解组。
选项#2 - @XmlAccessorType(XmlAccessType.NONE)
您可以使用@XmlAccessorType(XmlAccessType.NONE)
对类进行注释,以便只对带注释的字段/属性进行编组/解组。
了解更多信息