Skip to main content

[beginners question] serializing null attributes

No replies
Joined: 2006-08-22
Points: 0


I wanted to know if there is any way to configure JAXB to write null attribute as an empty string, and not just omit them from the xml.

for example, if i have this class:
@XmlElement(name = "aaa")
class A {
private String str;

@XmlAttribute(name = "str")
public String getStr() {

public void setStr(String str) {

the xml will look like this, when str=null:

I want it to be serialized as: