• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst
  • Peter Rooke
  • Mikalai Zaikin
Bartenders:
  • Himai Minh

JSON to XML Conversion

 
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have one JSON file and task is to convert into XML. Attached is my java file through, Getting an error at line 30 Exception in thread "main" java.lang.NoSuchMethodError: nu.xom.Serializer.getEncoding()Ljava/lang/String;. Please check.



Thanks
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have one JSON file and task is to convert into XML. Attached is my java file through, Getting an error at line 30 Exception in thread "main" java.lang.NoSuchMethodError: nu.xom.Serializer.getEncoding()Ljava/lang/String;


Make sure you have xom.jar in your classpath?
 
vivek dhiman
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

I got to know that I had the xom.jar file. & had the Serializer class in that, which doesn't have getEncoding() method. Thats the reason i am getting such error. These libraries provided by client so not able to alter . Trying to find out another solution.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vivek,

Please try the below code snippet.

JSONObject o = new JSONObject("{'glossary': {'title': 'example glossary','GlossDiv': {'title': 'S','GlossList': {'GlossEntry': {'ID': 'SGML','SortAs': 'SGML','GlossTerm': 'Standard Generalized Markup Language','Acronym': 'SGML','Abbrev': 'ISO 8879:1986','GlossDef': {'para': 'A meta-markup language, used to create markup languages such as DocBook.', 'GlossSeeAlso': ['GML', 'XML']},'GlossSee': 'markup'}} } } }");

String xml = org.json.XML.toString(o);

System.out.println(xml);

Above stuff should work with out adding any new jars. Try and let me know with the output.
 
Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad?
Master Gardener Program
https://coderanch.com/t/771761/Master-Gardener-Program
reply
    Bookmark Topic Watch Topic
  • New Topic