Example #1
0
  public static Object unmarshal(String msg, String userPackages[]) throws Exception {
    TreeSet<String> contextPackages = new TreeSet<String>();
    for (int i = 0; i < userPackages.length; i++) {
      String userPackage = userPackages[i];
      contextPackages.add(userPackage);
    }

    JAXBContext jaxbContext =
        JAXBUtils.getJAXBContext(
            contextPackages,
            constructionType,
            contextPackages.toString(),
            XmlUtils.class.getClassLoader(),
            new HashMap<String, Object>());
    Unmarshaller unmarshaller = JAXBUtils.getJAXBUnmarshaller(jaxbContext);
    Object o = unmarshaller.unmarshal(staxIF.createXMLStreamReader(new StringSource(msg)));
    JAXBUtils.releaseJAXBUnmarshaller(jaxbContext, unmarshaller);

    if (o instanceof JAXBElement) return ((JAXBElement) o).getValue();

    return o;
  }