2013-05-22 3 views
2
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이되기를 바란다.일부 변수를 XML 파일로 정렬하지 않으려면 어떻게해야합니까?

어떻게하면됩니까? - @XmlTransient

당신은 정렬 화 또는 비 정렬 화되는 필드/속성을 방지하기 위해 @XmlTransient 주석을 사용할 수 있습니다

옵션 # 1 :

답변

2

이 사용 사례를 지원하기위한 몇 가지 방법이 있습니다.

옵션 # 2-@XmlAccessorType(XmlAccessType.NONE)

는 당신은 주석 필드/속성/비 정렬 화, 정렬 화됩니다 그래서 @XmlAccessorType(XmlAccessType.NONE)와 클래스를 주석 할 수 있습니다. 추가 정보

+0

** OPTION-1 **. 마지막 질문은 POJO를 만들 때 기본값으로 초기화된다는 것입니다. :) –

+0

@LittleChild - 맞습니다. JAXB 구현은이 파일을 채우지 않으므로 사용자가 초기화하거나 기본값을 가져옵니다. –

관련 문제