Beispiel #1
0
  public void marshal(T object, boolean formatted, OutputStream outputStream)
      throws XMLStreamException, JAXBException, TransformerException, JSONException {
    Configuration writeConfig = new Configuration(xmlNamespaceToJsonPrefix);
    MappedXMLOutputFactory xof = new MappedXMLOutputFactory(writeConfig);

    XMLStreamWriter xmlStreamWriter = xof.createXMLStreamWriter(outputStream);

    JaxbHelper jaxbHelper = JaxbHelper.get(clazz);
    jaxbHelper.marshal(object, formatted, xmlStreamWriter);
  }
Beispiel #2
0
  public static Object unmarshal(XMLStreamReader xmlStreamReader, JaxbHelper jaxbHelper)
      throws JAXBException {
    // if (JETTISON_IS_FUBAR) {
    // // Jettison is screwed... it doesn't work unless we build a new stream reader from the xml
    // text.
    // // This is, of course, complete and utter nonsense
    // String xml = XmlHelper.toXml(xmlStreamReader);
    // xmlStreamReader = XmlHelper.buildXmlStreamReader(xml);
    // }

    Object obj = jaxbHelper.unmarshal(xmlStreamReader);
    return obj;
  }
Beispiel #3
0
  /** Accepts a 'bare' JSON format, and wraps in the appropriate outer element */
  public String wrapJson(String json) {
    String xmlElementName = JaxbHelper.getXmlElementName(clazz);
    String jsonClassName =
        xmlElementName; // Character.toLowerCase(jsonClassName.charAt(0)) +
                        // jsonClassName.substring(1);

    if (!json.startsWith("{")) {
      json = "{ " + json + " }";
    }
    json = "{\"" + jsonClassName + "\": " + json + " }";

    return json;
  }
Beispiel #4
0
 public void addDefaultNamespace() {
   JaxbHelper jaxbHelper = JaxbHelper.get(clazz);
   addNamespaceMapping(jaxbHelper.getPrimaryNamespace(), "");
 }
Beispiel #5
0
 private T unmarshal(XMLStreamReader xmlStreamReader)
     throws JAXBException, XMLStreamException, TransformerException {
   JaxbHelper jaxbHelper = JaxbHelper.get(clazz);
   Object obj = unmarshal(xmlStreamReader, jaxbHelper);
   return CastUtils.checkedCast(obj, clazz);
 }