0

I'm getting on line y setTypeHintsCompatibility( false ) is undefined for the type xmlserializer. What am i doing wrong exactly... Any help ?

 import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.*; 
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpServlet;
    import net.sf.json.JSON;
    import com.sun.org.apache.xml.internal.serialize.OutputFormat;
    import com.sun.org.apache.xml.internal.serialize.XMLSerializer;

    public class JsonForm extends HttpServlet {

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

            String str = "{'FirstName':'Mike'}";  
            JSON json = JSONSerializer.toJSON( str ); 
            XMLSerializer xmlSerializer = new XMLSerializer();  
            xmlSerializer.setTypeHintsCompatibility( false );  //Line y
            String xml = xmlSerializer.write( json );  
            System.out.println(xml); 


        }

    }
mikeb
  • 709
  • 2
  • 9
  • 35

1 Answers1

-1

Looking at this question: Change the com.sun.org.apache.xml.internal.serialize.XMLSerializer & com.sun.org.apache.xml.internal.serialize.OutputFormat I think you may be using Xerces.
If I understand correctly, such classes are included in your JVM and are not meant to be publicly used as you are trying to do. Change your code as explained here: Serialize DOM to FileOutputStream using Xerces .

If you are trying to convert JSON to XML, why don't you try this simpler approach? Converting JSON to XML in Java

Community
  • 1
  • 1
Alessandro Da Rugna
  • 4,571
  • 20
  • 40
  • 64