/**
   * Tests XmlAnyObjectMapping configuration via eclipselink-oxm.xml. Here an unmarshal operation is
   * performed. In this case, the 'any' is marked write-only, and should not be read in.
   *
   * <p>Positive test.
   */
  public void testAnyObjectWriteOnlyUnmarshal() {
    // load instance doc
    String src = PATH + "write-only-employee.xml";
    InputStream iDocStream = loader.getResourceAsStream(src);
    if (iDocStream == null) {
      fail("Couldn't load instance doc [" + src + "]");
    }
    JAXBContext jCtx = null;
    try {
      jCtx =
          createContext(
              new Class[] {Employee.class}, CONTEXT_PATH, PATH + "write-only-employee-oxm.xml");
    } catch (JAXBException e1) {
      fail("JAXBContext creation failed: " + e1.getMessage());
    }

    // unmarshal
    Employee ctrlEmp = getControlObject();
    ctrlEmp.stuff = null;
    Employee eObj = null;
    Unmarshaller unmarshaller = jCtx.createUnmarshaller();
    try {
      eObj = (Employee) unmarshaller.unmarshal(iDocStream);
      assertNotNull("Unmarshalled object is null.", eObj);
      assertTrue("Unmarshal failed:  Employee objects are not equal", ctrlEmp.equals(eObj));
    } catch (JAXBException e) {
      e.printStackTrace();
      fail("Unmarshal operation failed.");
    }
  }
 private void unmarshal(JAXBContext jCtx, String inputType, Object foo, String instanceDoc) {
   // setup control document
   Document ctrlDoc = parser.newDocument();
   try {
     ctrlDoc = getControlDocument(instanceDoc);
   } catch (Exception e) {
     e.printStackTrace();
     fail("An unexpected exception occurred loading control document [" + instanceDoc + "].");
   }
   // unmarshal
   Object obj = null;
   try {
     obj = jCtx.createUnmarshaller().unmarshal(ctrlDoc);
   } catch (JAXBException e) {
     e.printStackTrace();
     fail("An unexpected exception occurred during unmarshal [" + inputType + "]");
   }
   assertNotNull("Unmarshal [" + inputType + "] failed - returned object is null", obj);
   assertEquals("Unmarshal [" + inputType + "] failed - objects are not equal", obj, foo);
 }
Beispiel #3
0
 public Unmarshaller createUnmarshaller() throws JAXBException {
   return jaxbContext.createUnmarshaller();
 }