gatti
gatti

Reputation: 1132

JAXB Moxy mixed whitespace lost

I have a problem while unmarshalling an XML with mixed content. A space gets lost. The XML looks like this:

<text>rooms in <g>the</g> <g>Eldorado Hotel</g> on Broadway have a jacuzzi</text>

This is unmarshalled to:

Everything is fine but I'm missing the space between the two tags. I need to preserve that space!

The simplified mapping would be something like:

@XmlTransient
public abstract class AbstractText {

    private List words;

    @XmlMixed
    @XmlElementRefs({
        @XmlElementRef(type = WordGroup.class, required = false), // this is the <g> tag
        @XmlElementRef(type = Word.class, required = false)
    })
    public List getWords() {
        if (words == null) words = new ArrayList();
        return words;
    }

    public void setWords(List words) {
        this.words = words;
    }

}

@XmlRoot
public class Text extends AbstractText{

}

The mapping is not done exactly like this, but in an XML file (each class inherinting from AbstractText can have different children.

The real mapping is:

<java-type name="dp.dc.exercise.model.Text">
    <java-attributes>
        <xml-element-refs java-attribute="words" xml-mixed="true">
            <xml-element-ref type="dp.dc.exercise.model.text.Word" required="false"/>
            <xml-element-ref type="dp.dc.exercise.model.text.WordGroup" required="false"/>
        </xml-element-refs>
    </java-attributes>
</java-type>

and works great in everycase but when there are 2 tags, one after the other.

Any help will be highly appreciated :)

Upvotes: 3

Views: 256

Answers (1)

bdoughan
bdoughan

Reputation: 149047

This appears to be a bug, I have entered the following issue that you can track:

Upvotes: 1

Related Questions