Search in sources :

Example 1 with XMLSerializer

use of net.sf.json.xml.XMLSerializer in project fastjson by alibaba.

the class JSONLibXmlTest method test_xml.

public void test_xml() throws Exception {
    XMLSerializer xmlSerializer = new XMLSerializer();
    JSONObject json = new JSONObject();
    json.put("id", 123);
    json.put("name", "jobs");
    json.put("flag", true);
    JSONArray items = new JSONArray();
    items.add("x");
    items.add(234);
    items.add(false);
    json.put("items", items);
    String text = xmlSerializer.write(json);
    System.out.println(text);
}
Also used : XMLSerializer(net.sf.json.xml.XMLSerializer) JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray)

Example 2 with XMLSerializer

use of net.sf.json.xml.XMLSerializer in project camel by apache.

the class XmlJsonDataFormat method doStart.

@Override
protected void doStart() throws Exception {
    serializer = new XMLSerializer();
    if (forceTopLevelObject != null) {
        serializer.setForceTopLevelObject(forceTopLevelObject);
    }
    if (namespaceLenient != null) {
        serializer.setNamespaceLenient(namespaceLenient);
    }
    if (namespaceMappings != null) {
        for (NamespacesPerElementMapping nsMapping : namespaceMappings) {
            for (Entry<String, String> entry : nsMapping.namespaces.entrySet()) {
                // prefix, URI, elementName (which can be null or empty
                // string, in which case the
                // mapping is added to the root element
                serializer.addNamespace(entry.getKey(), entry.getValue(), nsMapping.element);
            }
        }
    }
    if (rootName != null) {
        serializer.setRootName(rootName);
    }
    if (elementName != null) {
        serializer.setElementName(elementName);
    }
    if (arrayName != null) {
        serializer.setArrayName(arrayName);
    }
    if (expandableProperties != null && expandableProperties.size() != 0) {
        serializer.setExpandableProperties(expandableProperties.toArray(new String[expandableProperties.size()]));
    }
    if (skipWhitespace != null) {
        serializer.setSkipWhitespace(skipWhitespace);
    }
    if (trimSpaces != null) {
        serializer.setTrimSpaces(trimSpaces);
    }
    if (skipNamespaces != null) {
        serializer.setSkipNamespaces(skipNamespaces);
    }
    if (removeNamespacePrefixes != null) {
        serializer.setRemoveNamespacePrefixFromElements(removeNamespacePrefixes);
    }
    if (typeHints == TypeHintsEnum.YES || typeHints == TypeHintsEnum.WITH_PREFIX) {
        serializer.setTypeHintsEnabled(true);
        if (typeHints == TypeHintsEnum.WITH_PREFIX) {
            serializer.setTypeHintsCompatibility(false);
        } else {
            serializer.setTypeHintsCompatibility(true);
        }
    } else {
        serializer.setTypeHintsEnabled(false);
        serializer.setTypeHintsCompatibility(false);
    }
}
Also used : XMLSerializer(net.sf.json.xml.XMLSerializer)

Example 3 with XMLSerializer

use of net.sf.json.xml.XMLSerializer in project tdi-studio-se by Talend.

the class Test method main.

/**
     * DOC wanghong Comment method "main".
     * 
     * @param args
     */
public static void main(String[] args) {
    try {
        File file = new File("D:/CLOUD_BPM_EE_MPX_generated.json");
        FileInputStream input = new FileInputStream(file);
        String jsonData = IOUtils.toString(input);
        XMLSerializer serializer = new XMLSerializer();
        JSON json = JSONSerializer.toJSON(jsonData);
        serializer.setRootName("JSONRoot");
        serializer.setTypeHintsEnabled(false);
        String xml = serializer.write(json);
        // System.out.println(xml);
        FileWriter writer = new FileWriter("D:/CLOUD.xml");
        writer.write(xml);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : XMLSerializer(net.sf.json.xml.XMLSerializer) FileWriter(java.io.FileWriter) JSON(net.sf.json.JSON) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 4 with XMLSerializer

use of net.sf.json.xml.XMLSerializer in project OpenClinica by OpenClinica.

the class ODMClinicaDataResource method getODMClinicaldata.

/**
     * @api {get} /rest/clinicaldata/json/view/:study/:subject/:event/:form Retrieve case report forms - JSON
     * @apiVersion 3.8.0
     * @apiName getODMClinicaldataJSON
     * @apiGroup Subject
     * @apiPermission user
     *
     * @apiDescription Annotated case report forms in printable HTML format. Use asterisks in place of OIDs as wildcards
     *
     * @apiParam {String} study Study or Site OID.
     * @apiParam {String} subject Subject Key or ID.
     * @apiParam {String} event Study Event Definition OID. Use '*' for all.
     * @apiParam {String} form Case Report Form Version OID. Use '*' for all.
     *
     *
     * @apiError NoAccessRight Only authenticated users can access the data.
     * @apiError NotFound The resource was not found.
     *
     */
@GET
@Path("/json/view/{studyOID}/{studySubjectIdentifier}/{studyEventOID}/{formVersionOID}")
@Produces(MediaType.APPLICATION_JSON)
public String getODMClinicaldata(@PathParam("studyOID") String studyOID, @PathParam("formVersionOID") String formVersionOID, @PathParam("studyEventOID") String studyEventOID, @PathParam("studySubjectIdentifier") String studySubjectIdentifier, @DefaultValue("n") @QueryParam("includeDNs") String includeDns, @DefaultValue("n") @QueryParam("includeAudits") String includeAudits, @Context HttpServletRequest request) {
    LOGGER.debug("Requesting clinical data resource");
    boolean includeDN = false;
    boolean includeAudit = false;
    if (includeDns.equalsIgnoreCase("no") || includeDns.equalsIgnoreCase("n"))
        includeDN = false;
    if (includeAudits.equalsIgnoreCase("no") || includeAudits.equalsIgnoreCase("n"))
        includeAudit = false;
    if (includeDns.equalsIgnoreCase("yes") || includeDns.equalsIgnoreCase("y"))
        includeDN = true;
    if (includeAudits.equalsIgnoreCase("yes") || includeAudits.equalsIgnoreCase("y"))
        includeAudit = true;
    int userId = ((UserAccountBean) request.getSession().getAttribute("userBean")).getId();
    XMLSerializer xmlSerializer = new XMLSerializer();
    FullReportBean report = getMetadataCollectorResource().collectODMMetadataForClinicalData(studyOID, formVersionOID, getClinicalDataCollectorResource().generateClinicalData(studyOID, getStudySubjectOID(studySubjectIdentifier, studyOID), studyEventOID, formVersionOID, includeDN, includeAudit, request.getLocale(), userId));
    if (report.getClinicalDataMap() == null)
        return null;
    report.createOdmXml(true);
    // xmlSerializer.setForceTopLevelObject(true);
    xmlSerializer.setTypeHintsEnabled(true);
    JSON json = xmlSerializer.read(report.getXmlOutput().toString().trim());
    JSONClinicalDataPostProcessor processor = new JSONClinicalDataPostProcessor(request.getLocale());
    processor.process((JSONObject) json);
    return json.toString(INDENT_LEVEL);
}
Also used : XMLSerializer(net.sf.json.xml.XMLSerializer) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) JSON(net.sf.json.JSON) FullReportBean(org.akaza.openclinica.bean.extract.odm.FullReportBean) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with XMLSerializer

use of net.sf.json.xml.XMLSerializer in project OpenClinica by OpenClinica.

the class MetadataCollectorResource method collectODMMetadataJson.

public JSON collectODMMetadataJson(String studyOID, String formVersionOID) {
    net.sf.json.xml.XMLSerializer xmlserializer = new XMLSerializer();
    JSON json = xmlserializer.read(collectODMMetadataForForm(studyOID, formVersionOID));
    return json;
}
Also used : XMLSerializer(net.sf.json.xml.XMLSerializer) XMLSerializer(net.sf.json.xml.XMLSerializer) JSON(net.sf.json.JSON)

Aggregations

XMLSerializer (net.sf.json.xml.XMLSerializer)7 JSON (net.sf.json.JSON)5 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 JSONArray (net.sf.json.JSONArray)1 JSONObject (net.sf.json.JSONObject)1 FullReportBean (org.akaza.openclinica.bean.extract.odm.FullReportBean)1 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)1 IProject (org.eclipse.core.resources.IProject)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 Project (org.talend.core.model.general.Project)1