--
You received this message because you are subscribed to the Google Groups "sdc-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sdc-user+unsubscribe@streamsets.com.
Visit this group at https://groups.google.com/a/streamsets.com/group/sdc-user/.
Hi Pat.Thanks reply me. You are being helpful!
I'm using these jar's dependencies:
commons-beanutils-1.9.3.jarcommons-collections-3.2.1.jarcommons-lang-2.5.jarcommons-logging-1.2.jarezmorph-1.0.6.jarjson-lib-2.4-jdk15.jarxom-1.2.5.jarBelow my xml-json class and my test project.I also have added the XML file and the result. I beautiful JSON clean and with no namespaces.
I believe I'm trying to do a hard stuff but I also believe it will be helpful for other sdc users.
============== JAVA CLASS ================package com.redfront;import net.sf.json.JSON;import net.sf.json.xml.XMLSerializer;public class converter {public String xmltojson (String xml) {XMLSerializer serializer = new XMLSerializer();serializer.setSkipNamespaces(true);serializer.setRemoveNamespacePrefixFromElements(true);serializer.setTrimSpaces(true);xml = xml.replaceAll(">\\s*<", "><");JSON json = serializer.read(xml);return json.toString();}}============== JAVA CLASS ============================== JAVA EXAMPLE =============package xmljson.example;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import com.redfront.converter;
public class FileToStringJava8 {
public static void main(String args[]) throws IOException {
String fileString = new String(Files.readAllBytes(Paths.get("/tmp/x.xml")), StandardCharsets.UTF_8);
System.out.println(fileString);
converter c = new converter();
String json = c.xmltojson(fileString);
System.out.println(json);
}
}
============== JAVA EXAMPLE =============
Regards,Douglas.
$ cat /tmp/out/2018-04-03-17/sdc-24e75fba-bd00-42fd-80c3-1f591e200ca6_55f4139c-3011-4fbd-9c5e-d7afd23e2253 | jq .
{
"entity-PolicyChange": {
"ExceptionHandlingType_Ext": "NotApplicable_Ext"
},
"CloseDate": "2017-08-08T17:02:55.936-07:00",
"CreateTime": "2017-08-08T17:02:38.301-07:00",
"CreateUser": {
"Contact": {
"AddressBookUID": "pcuser:N7SB",
"FirstName": "FFF-NNN001",
"LastName": "LLL-NNN001",
"PublicID": "FROT:7911"
},
"Credential": {
"UserName": "N7SB"
},
"PublicID": "FROT:7568"
},