Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making @XmlTransient annotation just for serializing?

I use Spring and Apache CXF for my project that implements java Web Services with first-code style.

I have a variable as defined:

@XmlTransient
public String word;

So that variable doesn't map to an attribute at XML.

However I want it to be ignored to mapping XML element at serialization but not at deserialization.

How can I do that?

like image 775
kamaci Avatar asked Mar 21 '26 12:03

kamaci


1 Answers

I don't think you can achieve that with @XmlTransient. An option would be to use MOXy to marshal using one schema and unmarshal using another schema. You can find a great example here.

A simple but less elegant workaround would be something like this:

@XmlTransient
public String word;

public void setDeserializedWord(String word) {
   this.word = word;
}

@XmlElement(name="word")
public String getDeserializedWord() {
   return null;
}
like image 149
tibtof Avatar answered Mar 24 '26 03:03

tibtof