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);
}
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);
}
}
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();
}
}
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);
}
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;
}
Aggregations