Package org.codehaus.jettison.json

Examples of org.codehaus.jettison.json.JSONTokener


            if (charset == null) {
                charset = "UTF-8";
            }
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            copy(is, bos, 1024);
            return createXMLStreamReader(new JSONTokener(new String(bos.toByteArray(), charset)));
        } catch (IOException e) {
            throw new XMLStreamException(e);
        }
    }
View Full Code Here


          int len;
          char[] buf = new char[1024];
            while ((len = reader.read(buf)) != -1) {
              wrt.write(buf, 0, len);
            }
            return createXMLStreamReader(new JSONTokener(wrt.toString()));
        } catch (IOException e) {
            throw new XMLStreamException(e);
        }
    }
View Full Code Here

    }

    public static FaunusVertex fromJSON(String line) throws IOException {
        try {
            final JSONObject json = new JSONObject(new JSONTokener(line));
            line = EMPTY_STRING; // clear up some memory

            final FaunusVertex vertex = (FaunusVertex) graphson.vertexFromJson(json);

            fromJSONEdges(vertex, json.optJSONArray(_OUT_E), OUT);
View Full Code Here

    static JSONObject get(final String uri) {
        try {
            final URLConnection connection = createConnection(uri, null, RexsterTokens.APPLICATION_REXSTER_TYPED_JSON);
            connection.connect();
            return new JSONObject(new JSONTokener(convertStreamToString(connection.getInputStream())));
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
View Full Code Here

            if (noResult) {
                new InputStreamReader(connection.getInputStream()).close();
                return null;
            } else {
                return new JSONObject(new JSONTokener(convertStreamToString(connection.getInputStream())));
            }
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
View Full Code Here

    @Test
    public void vertexFromJsonValid() throws IOException, JSONException {
        Graph g = new TinkerGraph();
        ElementFactory factory = new GraphElementFactory(g);

        Vertex v = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.NORMAL, null);

        Assert.assertSame(v, g.getVertex(1));

        // tinkergraph converts id to string
        Assert.assertEquals("1", v.getId());
View Full Code Here

    public void vertexFromJsonExtendedTypesValid() throws IOException, JSONException {
        // need to test those data types that are not covered by the toy graphs
        Graph g = new TinkerGraph();
        ElementFactory factory = new GraphElementFactory(g);

        Vertex v = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson3)), factory, GraphSONMode.EXTENDED, null);

        Assert.assertSame(v, g.getVertex(1));

        Assert.assertEquals((byte) 4, v.getProperty("byteValue"));
        Assert.assertEquals(new Short("10"), v.getProperty("shortValue"));
View Full Code Here

        Set<String> ignoreAge = new HashSet<String>();
        ignoreAge.add("age");
        ElementPropertyConfig config = ElementPropertyConfig.excludeProperties(ignoreAge, null);
        GraphSONUtility utility = new GraphSONUtility(GraphSONMode.NORMAL, factory, config);
        Vertex v = utility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)));

        Assert.assertSame(v, g.getVertex(1));

        // tinkergraph converts id to string
        Assert.assertEquals("1", v.getId());
View Full Code Here

    @Test
    public void edgeFromJsonValid() throws IOException, JSONException {
        Graph g = new TinkerGraph();
        ElementFactory factory = new GraphElementFactory(g);

        Vertex v1 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.NORMAL, null);
        Vertex v2 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)), factory, GraphSONMode.NORMAL, null);
        Edge e = GraphSONUtility.edgeFromJson(new JSONObject(new JSONTokener(edgeJson)), v1, v2, factory, GraphSONMode.NORMAL, null);

        Assert.assertSame(v1, g.getVertex(1));
        Assert.assertSame(v2, g.getVertex(2));
        Assert.assertSame(e, g.getEdge(7));
View Full Code Here

    @Test
    public void edgeFromJsonIgnoreWeightValid() throws IOException, JSONException {
        Graph g = new TinkerGraph();
        ElementFactory factory = new GraphElementFactory(g);

        Vertex v1 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.NORMAL, null);
        Vertex v2 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)), factory, GraphSONMode.NORMAL, null);

        Set<String> ignoreWeight = new HashSet<String>();
        ignoreWeight.add("weight");
        ElementPropertyConfig config = ElementPropertyConfig.excludeProperties(null, ignoreWeight);
        GraphSONUtility utility = new GraphSONUtility(GraphSONMode.NORMAL, factory, config);
        Edge e = utility.edgeFromJson(new JSONObject(new JSONTokener(edgeJson)), v1, v2);

        Assert.assertSame(v1, g.getVertex(1));
        Assert.assertSame(v2, g.getVertex(2));
        Assert.assertSame(e, g.getEdge(7));
View Full Code Here

TOP

Related Classes of org.codehaus.jettison.json.JSONTokener

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.