Exception in thread "main" java.lang.NoSuchMethodError: nu.xom.Serializer.getEncoding()Ljava/lang/String;.

Exception in thread "main" java.lang.NoSuchMethodError: nu.xom.Serializer.getEncoding()Ljava/lang/String;.

 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.

import java.io.InputStream;  
 
import net.sf.json.JSON;  
import net.sf.json.JSONSerializer;  
import net.sf.json.xml.JSONTypes;  
import net.sf.json.xml.XMLSerializer;  
 
import org.apache.commons.io.IOUtils;  
import org.json.JSONObject;  
 
 
public class temp {  
 
    public static void main(String[] args) throws Exception  
    {  
        try 
    {  
          
              
        InputStream is = temp.class.getResourceAsStream("manifest.json");  
        String jsonData = IOUtils.toString(is);  
        System.out.println(jsonData);  
        JSONObject jObj=new JSONObject(jsonData);  
          
        XMLSerializer serializer = new XMLSerializer();   
        JSON json = JSONSerializer.toJSON(jsonData);   
        System.out.println(jsonData);  
        System.out.println(json);  
        serializer.setRootName("SampleJSON");  
        String xml1 = serializer.write(json);  
        System.out.println(xml1);         
          
    }  
        catch(Exception e)  
        {  
            e.printStackTrace();  
        }  
}  

import java.io.InputStream;

import net.sf.json.JSON;
import net.sf.json.JSONSerializer;
import net.sf.json.xml.JSONTypes;
import net.sf.json.xml.XMLSerializer;

import org.apache.commons.io.IOUtils;
import org.json.JSONObject;


public class temp {

 public static void main(String[] args) throws Exception
 {
  try
 {
  
   
  InputStream is = temp.class.getResourceAsStream("manifest.json");
  String jsonData = IOUtils.toString(is);
  System.out.println(jsonData);
  JSONObject jObj=new JSONObject(jsonData);
  
  XMLSerializer serializer = new XMLSerializer();
  JSON json = JSONSerializer.toJSON(jsonData);
  System.out.println(jsonData);
  System.out.println(json);
  serializer.setRootName("SampleJSON");
  String xml1 = serializer.write(json);
  System.out.println(xml1);    
  
 }
  catch(Exception e)
  {
   e.printStackTrace();
  }
}
}
 
Make sure you have xom.jar in your classpath? 
 
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.

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright