title: Unable to marshal type as XML element because @XmlRootElement annotation is missing
body: <p>I want to marshal object to XML. </p>
  
  <p>However, it fails with exception:</p>
  
  <pre><code>javax.xml.bind.MarshalException
   - with linked exception:
  [com.sun.istack.SAXException2: unable to marshal type "FreightOfferDetail" as an element because it is missing an @XmlRootElement annotation]
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:331)
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:257)
      at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:96)
      at com.wktransportservices.fx.test.util.jaxb.xmltransformer.ObjectTransformer.toXML(ObjectTransformer.java:27)
      at com.wktransportservices.fx.test.sampler.webservice.connect.FreightOfferToConnectFreight.runTest(FreightOfferToConnectFreight.java:59)
      at org.apache.jmeter.protocol.java.sampler.JavaSampler.sample(JavaSampler.java:191)
      at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:429)
      at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257)
      at java.lang.Thread.run(Thread.java:662)
  Caused by: com.sun.istack.SAXException2: unable to marshal type "FreightOfferDetail" as an element because it is missing an @XmlRootElement annotation
      at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:244)
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:303)
      at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:490)
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328)
  </code></pre>
  
  <p>In fact, this annotation is present (for parent and delivered class):</p>
  
  <pre><code>@XmlRootElement(name = "Freight_Offer")
  @XmlAccessorType(XmlAccessType.FIELD)
  @JsonIgnoreProperties(ignoreUnknown = true)
  @JsonInclude(JsonInclude.Include.NON_EMPTY)
  public class FreightOffer {
      @JsonIgnore
      @XmlTransient
      private String freightId;
      private String id;
  
      private String externalSystemId;
  
      private AddressLocation pickUp;
  
      private AddressLocation delivery;
  
      private FreightDescription freightDescription;
  
      private ListContacts contacts;
  
      private Customer customer;
  
      private ListSla slas;
  
      private String pushId;
  
      private CompanyProfile company;
  
      private Route route;
  
      private String href;
  
      private Lifecycle lifecycle;
  
      private Visibility visibility;
  
      private Boolean unfoldedVXMatching;
      // getters / setters
  </code></pre>
  
  <p>Child class:</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.PROPERTY)
  public class FreightOfferDetail extends FreightOffer {
  
      private List&lt;Contact&gt; contact;
  
      @XmlElement(name = "contacts")
      @JsonProperty("contacts")
      public List&lt;Contact&gt; getContact() {
          return contact;
      }
  
      public void setContact(List&lt;Contact&gt; contact) {
          this.contact = contact;
      }
  </code></pre>
  
  <p>It fails exactly at this method <code>toXML()</code>:</p>
  
  <pre><code>public class ObjectTransformer&lt;T&gt; implements Transformer&lt;T&gt; {
  
      protected final JAXBContext context;
      protected final Marshaller marshaller;
  
      protected final int okStatusCode = 200;
      protected final String okSubErrorCode = "OK";
  
      public ObjectTransformer(JAXBContext context) throws JAXBException {
          this.context = context;
          marshaller = context.createMarshaller();
          marshaller.setProperty("jaxb.encoding", "UTF-8");
          marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
      }
  
      public String toXML(T object) throws JAXBException {
          StringWriter writer = new StringWriter();
          marshaller.marshal(object, writer);
          String xmlOffer = writer.toString();
          return xmlOffer;
      }
  </code></pre>
  
  <p>It should work, but it shouldn't. </p>
  
  <p>I couldn't find what is missed or wrong here.</p>
  
  <p><strong><em>UPDATE:</em></strong></p>
  
  <p>Here is snippet from test:</p>
  
  <pre><code>public SampleResult runTest(JavaSamplerContext context) {
      AbstractSamplerResults results = new XMLSamplerResults(new SampleResult());
      results.startAndPauseSampler();
  
      if (failureCause != null) {
          results.setExceptionFailure("FAILED TO INSTANTIATE connectTransformer", failureCause);
      } else {
          FreightOfferDTO offer = null;
          FreightOffer freightOffer = null;
          try {
              results.resumeSampler();            
  
              RouteInfo routeDTO = SamplerUtils.getRandomRouteFromRepo(context.getIntParameter(ROUTES_TOUSE_KEY));
  
              offer = FreightProvider.createRandomFreight(routeDTO, createUserWithLoginOnly(context));
  
              freightOffer = connectTransformer.fromDTO(offer);
              String xmlOfferString = connectTransformer.toXML(freightOffer); // &lt;- it fails here.
  </code></pre>
  
  <p>I take the date from <strong><em>CSV</em></strong> file and converting to <strong><em>DTO</em></strong> object. This method returns to me 
  <code>FreightOfferDetail.</code></p>
  
  <p>Here is snippet from this method:</p>
  
  <pre><code>public FreightOfferDetail freightFromDTO(FreightOfferDTO freightDTO, boolean fullFormat){
      FreightOfferDetail freight = new FreightOfferDetail();
  
      freight.setFreightId(freightDTO.getIds().getAtosId());
      freight.setId(freightDTO.getIds().getFxId());
      // ...
  </code></pre>
  
  <p><strong><em>How to marshal object to XML file, at this case?</em></strong></p>