Hello, dear.

There is a third-party library (for obvious reasons not modifiable), I inherit my class from one of its abstract classes. Then I serialize this class with JAXB and give it over SOAP (I only connect the enterprise, I don’t pull the libraries separately, everything from the javax package).

Problem: JAXB grabs the fields of an abstract (super) class, which is undesirable (they are not even described in xsd, and therefore are rendered without namespace).

Question: how to ignore all fields of all superclasses, or how to ignore all fields that are not marked with @XmlElement ?

I tried the following:

  1. @XmlAccessorType(XmlAccessType.NONE) to the current class (which, in fact, goes to serialize)
  2. Tried to make an intermediate class, and @XmlTransient on it
  3. I tried to rewrite the getters of the fields that @XmlTransient me, and @XmlTransient on them

None of this helps, it feels like JAXB just scored on annotations ...

Here is what I get:

 <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <S:Body> <ns3:GetBonusStatusRequest xmlns:ns3="http://some.soap.wsdl.ru/path/to/them/SelfCarePortal"> <execDelay>0</execDelay> <name>com.xxx.protocol.sip.impl.GetBonusStatusSipRequest</name> <poolId>sip</poolId> <ns3:svcNum>xxxxxx</ns3:svcNum> <ns3:SAN>xxxxxxx</ns3:SAN> </ns3:GetBonusStatusRequest> </S:Body> 

Accordingly, I do not need the execDelay, name, poolId fields, they are not described by the protocol. Jackson, for example, is able to @JsonIgnoreProperties({"poolId", "frontendId", "name", "execDate", "execDelay", "cancelled"}) but JAXB has pumped something ...

    1 answer 1

    1. It is necessary to mark the parent class @XmlTransient
    2. JAXB's EclipseLink has a solution to this problem ( http://wiki.eclipse.org/EclipseLink/Examples/MOXy/EclipseLink-OXM.XML ) as an example of working with the annotation
     <java-types> <java-type name="java.util.logging.LogRecord" xml-transient="true"/> </java-types>