Package net.sf.json.xml

Examples of net.sf.json.xml.XMLSerializer


      result = "";
    return result;
  }

  public String toXML() {
    return new XMLSerializer().write(JSONObject.fromObject(this,
        JsonConfigFactory.createJsonConfig(this.content)));
  }
View Full Code Here


        return JSONObject.fromObject(obj, config);
    }

    public String toXML(Object obj) {
        JSON json = _toJson(obj);
        XMLSerializer xmlSerializer = new XMLSerializer();
        return xmlSerializer.write(json);
    }
View Full Code Here

        return (JSONObject) json;
    }

    private JSON _contentAsXML() {
        try {
            XMLSerializer xmlSerializer = new XMLSerializer();
            JSON json = xmlSerializer.read(contentAsString());
            return json;
        } catch (Exception e) {
            throw new ArgumentErrorException("数据格式错误,您需要传入json格式");
        }
    }
View Full Code Here

        }

        @Override
        public void run() {
            log.debug("Running handler...");
            final XMLSerializer serializer = new XMLSerializer();
            JSONObject json = null;

            try {
                json = (JSONObject)JSONSerializer.toJSON(new String(packetData));
            } catch(ClassCastException e) {
                log.error("Error converting packet to JSON: " + e.getMessage());
                return;
            } catch(Exception e) {
                log.error("Got exception: " + e.getMessage());
                return;
            }

            // check for a timestamp, and add if not already there
            if(!json.has("timestamp")) {
                json.put("timestamp", new Date().getTime());
            }

            // set the root to the event output name
            serializer.setRootName(config.getEventOutputName());

            final String xml = serializer.write(json);
            final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

            try {
                final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                final Document document = dBuilder.parse(new ByteArrayInputStream(xml.getBytes()));
View Full Code Here

      String content = response.getContentAsString().trim();
      if( !StringUtils.hasContent( content ) )
        return null;

      JSON json = JSONSerializer.toJSON( content );
      XMLSerializer serializer = new XMLSerializer();
      serializer.setTypeHintsEnabled( false );
      serializer.setRootName( HttpUtils.isErrorStatus( response.getStatusCode() ) ? "Fault" : "Response" );
      URL url = response.getURL();
      serializer.setNamespace( "", url.getProtocol() + "://" + url.getHost() + url.getPath() );
      content = serializer.write( json );
      content = XmlUtils.prettyPrintXml( content );

      return content;
    }
    catch( Throwable e )
View Full Code Here

    public XmlJsonDataFormat() {
    }

    @Override
    protected void doStart() throws Exception {
        serializer = new XMLSerializer();

        if (forceTopLevelObject != null) {
            serializer.setForceTopLevelObject(forceTopLevelObject);
        }
View Full Code Here

    public XmlJsonDataFormat() {
    }

    @Override
    protected void doStart() throws Exception {
        serializer = new XMLSerializer();

        if (forceTopLevelObject != null) {
            serializer.setForceTopLevelObject(forceTopLevelObject);
        }
View Full Code Here

    public XmlJsonDataFormat() {
    }

    @Override
    protected void doStart() throws Exception {
        serializer = new XMLSerializer();

        if (forceTopLevelObject != null) {
            serializer.setForceTopLevelObject(forceTopLevelObject);
        }
View Full Code Here

import net.sf.json.JSONObject;
import net.sf.json.xml.XMLSerializer;

public class JSONLibXmlTest extends TestCase {
    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);
    }
View Full Code Here

     * @param xml the XML string
     *
     * @return a JSONObject
     */
    public static JSONObject xmlToJSON(String xml) {
        return ((JSONObject)new XMLSerializer().read(xml));
    }
View Full Code Here

TOP

Related Classes of net.sf.json.xml.XMLSerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.