title: XML marshalling of surrogate pairs
body: <p>I have came across a strange behavior of marshaller when surrogate pairs are involved. Why JAXB marshaller adds unnecessary (and invalid) XML entity? When I try to marshall the following:</p>
  <ul>
  <li><em>\uD83D\uDCB3, e.g. 55357 56499 code points</em></li>
  </ul>
  <p>Mashaller outputs 128179 code point (that is valid and represents both surrogate pairs in XML) and unnecessary 56499 (which is not a valid XML entity and represents low part of pair). <strong>How can I configure marshaller to achieve valid XML entities in output</strong>, or do I need just upgrade libraries? I am using Java 8.</p>
  <p>Sample reproducing code:</p>
  <pre><code>    String inputSurrogate = &quot;\uD83D\uDCB3&quot;;
      JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
  
      Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
      jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
      jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, &quot;UTF-8&quot;);
      StringWriter sw = new StringWriter();
  
      Customer customer = new Customer();
      customer.setText(inputSurrogate);
      jaxbMarshaller.marshal(customer, sw);
      String xmlString = sw.toString();
  
      System.out.println(xmlString);
      for (int i = 0; i &lt; xmlString.length(); i++) {
          int ch = xmlString.codePointAt(i);
          System.out.print(ch);
          System.out.print(&quot;|&quot;);
      }
  </code></pre>
  <p>Output (note the |128179|56499|, the 56499 is unnecessary and invalid to my understanding):</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
  &lt;customer&gt;
      &lt;text&gt;&lt;/text&gt;
  &lt;/customer&gt;
  </code></pre>
  <p>60|63|120|109|108|32|118|101|114|115|105|111|110|61|34|49|46|48|34|32|101|110|99|111|100|105|110|103|61|34|85|84|70|45|56|34|32|115|116|97|110|100|97|108|111|110|101|61|34|121|101|115|34|63|62|10|60|99|117|115|116|111|109|101|114|62|10|32|32|32|32|60|116|101|120|116|62|128179|56499|60|47|116|101|120|116|62|10|60|47|99|117|115|116|111|109|101|114|62|10|</p>