Package net.sf.json

Examples of net.sf.json.JSON


    @Test
    public void testUnmarshalJSONObject() throws Exception {
        InputStream inStream = getClass().getResourceAsStream("testMessage1.json");
        String in = context.getTypeConverter().convertTo(String.class, inStream);
        JSON json = JSONSerializer.toJSON(in);

        MockEndpoint mockXML = getMockEndpoint("mock:xml");
        mockXML.expectedMessageCount(1);
        mockXML.message(0).body().isInstanceOf(String.class);
View Full Code Here


                    try {
                        Writer outWriter = new BufferedWriter(new OutputStreamWriter(os));

                        outWriter.flush();

                        JSON obj = (JSON)toJSONObject(o);

                        obj.write(outWriter);
                        outWriter.flush();
                    } catch (Exception e) {
                        try {
                            // how to handle?
                            os.write(("Couldn't write json because of " + e.toString()).getBytes());
                            e.printStackTrace();
                        } catch (IOException ioe) {
                        }
                    }
                }

                public Object toJSONObject(Object obj) {
                    if (obj instanceof Map) {
                        Map m = (Map) obj;
                        JSONObject json = new JSONObject();
                        Iterator it = m.entrySet().iterator();

                        while (it.hasNext()) {
                            Map.Entry entry = (Map.Entry) it.next();
                            json.put((String) entry.getKey(), toJSONObject(entry.getValue()));
                        }

                        return json;
                    } else if (obj instanceof Collection) {
                        Collection col = (Collection) obj;
                        JSONArray json = new JSONArray();
                        Iterator it = col.iterator();

                        while (it.hasNext()) {
                            json.add(toJSONObject(it.next()));
                        }

                        return json;
                    } else if (obj instanceof Number) {
                        return obj;
                    } else if (obj == null) {
                        return JSONNull.getInstance();
                    } else {
                        return obj.toString();
                    }
                }
            };
    }
View Full Code Here

import net.sf.json.JSONObject;
import org.geoserver.test.GeoServerTestSupport;

public class SmokeTest extends GeoServerTestSupport {
    public void testServiceExists() throws Exception {
        JSON json = getAsJSON("/pdf/info.json");

        assertTrue(json instanceof JSONObject);
        JSONObject obj = (JSONObject) json;
        assertTrue(obj.containsKey("scales"));
        assertTrue(obj.containsKey("dpis"));
View Full Code Here

        List<StyleInfo> styles = catalog.getStyles();
        assertXpathEvaluatesTo(""+styles.size(), "count(//style)", dom);
    }
   
    public void testGetAllASJSON() throws Exception {
        JSON json = getAsJSON("/rest/styles.json");
        List<StyleInfo> styles = catalog.getStyles();
        assertEquals( styles.size(),
            ((JSONObject) json).getJSONObject("styles").getJSONArray("style").size());
    }
View Full Code Here

        assertXpathEvaluatesTo("Ponds", "/style/name", dom);
        assertXpathEvaluatesTo("Ponds.sld", "/style/filename", dom);
    }
   
    public void testGetAsJSON() throws Exception {
        JSON json = getAsJSON( "/rest/styles/Ponds.json");
       
        JSONObject style =  ((JSONObject)json).getJSONObject("style");
        assertEquals( "Ponds", style.get( "name") );
        assertEquals( "Ponds.sld", style.get( "filename") );
    }
View Full Code Here

        assertEquals( catalog.getStoresByWorkspace( "sf", DataStoreInfo.class ).size(),
            dom.getElementsByTagName( "dataStore").getLength() );
    }
   
    public void testGetAllAsJSON() throws Exception {
        JSON json = getAsJSON( "/rest/workspaces/sf/datastores.json");
        assertTrue( json instanceof JSONObject );
       
        Object datastores = ((JSONObject)json).getJSONObject("dataStores").get("dataStore");
        assertNotNull( datastores );
       
View Full Code Here

        DataStore ds = (DataStore) newDataStore.getDataStore(null);
        assertNotNull(ds);
    }
   
    public void testGetAsJSON() throws Exception {
        JSON json = getAsJSON( "/rest/workspaces/sf/datastores/sf.json" );
       
        JSONObject dataStore = ((JSONObject)json).getJSONObject("dataStore");
        assertNotNull(dataStore);
       
        assertEquals( "sf", dataStore.get( "name") );
View Full Code Here

        Response response = new Response(request);
       
        FooReflectiveResource resource = new FooReflectiveResource( null, request, response );
        resource.handleGet();
       
        JSON json = getJSON(response);
       
        JSONObject foo = ((JSONObject)json).getJSONObject(Foo.class.getName());
        assertNotNull( foo );
       
        assertEquals("one", foo.get( "prop1" ) );
View Full Code Here

        Writer outWriter = new BufferedWriter(new OutputStreamWriter(out));

        //JD: why does this initial flush occur?
        outWriter.flush();

        JSON obj = (JSON)toJSONObject(object);

        obj.write(outWriter);
        outWriter.flush();
    }
View Full Code Here

        assertXpathEvaluatesTore.getMinY()+"" , "/featureType/latLonBoundingBox/miny", dom );
        assertXpathEvaluatesTore.getMaxY()+"" , "/featureType/latLonBoundingBox/maxy", dom );
    }
   
    public void testGetAsJSON() throws Exception {
        JSON json = getAsJSON( "/rest/workspaces/sf/featuretypes/PrimitiveGeoFeature.json");
        JSONObject featureType = ((JSONObject)json).getJSONObject("featureType");
        assertNotNull(featureType);
       
        assertEquals( "PrimitiveGeoFeature", featureType.get("name") );
        assertEquals( CRS.decode("EPSG:4326").toWKT(), featureType.get( "nativeCRS") );
View Full Code Here

TOP

Related Classes of net.sf.json.JSON

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.