Not introducing CDATA with just one value
Asked Answered
F

0

8

My Wrapper class is this:

@XmlRootElement(name = "GETA")
public class EfGetAResponseWrapperXmlObject {

    private String something;


    @XmlElement(name = "result")
    public String getSomething() {
        return something;
    }

    public void setSomething(String something) {
        this.something = something;
    }

}

For this wrapper class I get this answer on SoapUI:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
       <S:Body>
          <ns2:ef_getAresponse xmlns:ns2="http://service.package/">
             <ef_get_AReturn>&lt;GETA>
        &lt;result>mystring&lt;/result>
    &lt;/GETA></ef_get_AReturn>
          </ns2:ef_get_AResponse>
       </S:Body>
    </S:Envelope>

If I introduce one more variable to my Wrapper class:

@XmlRootElement(name = "GETA")
    public class EfGetAResponseWrapperXmlObject {

        private String something;
        private String other;


        @XmlElement(name = "result")
        public String getSomething() {
            return something;
        }

        public void setSomething(String something) {
            this.something = something;
        }

        public String getOther() {
            return other;
        }
        public void setOther(String other) {
            this.other = other;
        }
    }

I get this answer:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:ef_getAresponse xmlns:ns2="http://service.package/">
         <ef_get_AReturn><![CDATA[<GETA>
    <result>fasf</result>
    <other>fds</other>
</GETA>]]></ef_get_AReturn>
      </ns2:ef_getAresponse>
   </S:Body>
</S:Envelope>

I dont understand this behaviour. I want to have the same answer on the first case that I have on second case. How can I do this?

Foulmouthed answered 28/3, 2015 at 0:4 Comment(4)
forums.asp.net/t/….Quality
Have you tried annotating the field with @XmlTransient as in https://mcmap.net/q/349548/-excluding-fields-in-jaxbReprobative
Do you mean that the first response is generated with all the "<" escaped? The primary reason why JAXB/JAXWS will automatically "CDATA" your response is if there's markup or some other escape-worthy content in there. Your second response doesn't look like that would have been necessary. Perhaps you should look into your ObjectFactory as to why it's happening. To resolve, just use the recommendation from carcaretSkillless
The problem is in response. If I have a short answer I do not have ![CDATA[]]. It´s not a java implementation problem, as you answered. In browser I don ´t get: &lt;result>mystring&lt;/result> &lt;/GETA></ef_get_AReturn> I get with CDATA. So the problem is in SoapUI.Foulmouthed

© 2022 - 2024 — McMap. All rights reserved.