2

This is the XML output I currently get:

<parameter>
  <dataIdentifier>123</dataIdentifier>
  <newValue encoding="base64">
     <value>NjUw</value>
  </newValue>
</parameter>

And this is the XML output I want to have:

<parameter>
  <dataIdentifier>123</dataIdentifier>
  <newValue encoding="base64">NjUw</newValue>
</parameter>

Here are my Java classes so far:

@XmlRootElement(name = "parameter")
public class Parameter {

    private Integer dataIdentifier;
    private ParameterValue newValue;
  ..
}

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ParameterValue {

    @XmlAttribute(name="encoding") 
    private String encoding;
    private String value;
  ..
}

I am sure there is an easy solution for my problem. Unfortunately I do not have any idea about JAXB annotations. I already invested a few hours but I can't find a way to do it. Can someone please show me how to solve this?

Thanks

Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
Zensursula
  • 173
  • 4
  • 9

1 Answers1

3

You must use following class

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ParameterValue {

    @XmlAttribute(name="encoding") private String encoding;
    @XmlValue private String value;
  ..
}
Xstian
  • 8,184
  • 10
  • 42
  • 72
  • Hi Xstian, many, many thanks! Life can be so easy sometimes. It works now! Will accept this as answer, when stackoverflow has unlocked the answer field – Zensursula Sep 13 '16 at 12:44