Package net.minidev.json

Examples of net.minidev.json.JSONObject


    throws Exception {

    JWTClaimsSet claimsSet = new JWTClaimsSet();
    claimsSet.setAudience("123");

    JSONObject jsonObject = claimsSet.toJSONObject();

    assertEquals("123", (String)jsonObject.get("aud"));
    assertEquals(1, jsonObject.size());

    claimsSet = JWTClaimsSet.parse(jsonObject.toJSONString());
    assertEquals("123", claimsSet.getAudience().get(0));
    assertEquals(1, claimsSet.getAudience().size());
  }
View Full Code Here


*/
public class JsonVrecordFormatter implements VrecordFormatter {

  @Override
  public StringWriter vrecordWriter(VertexRecord vrec) {
    JSONObject obj = new JSONObject();
    obj.put("gvid", vrec.vid());
    obj.put("owner", vrec.owner());
    obj.put("inEdges", vrec.inEdges());
    obj.put("outEdges", vrec.outEdges());
    obj.put("mirrors", vrec.mirrorList());
    obj.put("vdata", vrec.vdata());
    StringWriter out = new StringWriter();
    try {
      obj.writeJSONString(out);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return out;
  }
View Full Code Here

*/
public class SimpleJsonFormatter implements EdgeFormatter {

  @Override
  public StringWriter structWriter(Graph g) {
    JSONObject obj = new JSONObject();
    StringWriter out = new StringWriter();
    int count = 0;
    List sortedKey = ((SimpleGraph) g).vertices();
    Collections.sort(sortedKey);
    try {
      for (int i = 0; i < sortedKey.size(); i++) {
        obj.clear();
        obj.put("source", sortedKey.get(i));
        obj.put("targets", ((SimpleGraph) g).outEdgeTargetIds(sortedKey.get(i)));
        obj.writeJSONString(out);
        out.append("\n");
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
View Full Code Here

  /**
   * @return the JSON encoding.
   */
  public JSONObject toJSONObj() {
    JSONObject obj = new JSONObject();
    obj.put("rowIndex", rowIndex);
    obj.put("colIndex", colIndex);
    return obj;
  }
View Full Code Here

  /**
   * @param g
   * @return A JSON string of the vid2lvid map of a GLGraph.
   */
  public StringWriter vid2lvidWriter(GLGraph g) {
    JSONObject obj = new JSONObject();
    obj.put("vid2lvid", g.vid2lvid());
    StringWriter out = new StringWriter();
    try {
      obj.writeJSONString(out);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return out;
  }
View Full Code Here

    return out;
  }

  @Override
  public StringWriter edataWriter(Graph g) {
    JSONObject obj = new JSONObject();
    obj.put("edataList", ((GLGraph) g).edatalist());
    StringWriter out = new StringWriter();
    try {
      obj.writeJSONString(out);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return out;
  }
View Full Code Here

    return out;
  }

  @Override
  public StringWriter structWriter(Graph graph) {
    JSONObject obj = new JSONObject();
    GLGraph g = (GLGraph) graph;
    obj.put("numVertices", g.numVertices());
    obj.put("numEdges", g.numEdges());
    obj.put("csr", g.csr().toJSONObj());
    obj.put("csc", g.csc().toJSONObj());
    obj.put("c2rMap", g.c2rMap());
    StringWriter out = new StringWriter();
    try {
      obj.writeJSONString(out);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return out;
  }
View Full Code Here

  public void map(LongWritable arg0, Text arg1,
      OutputCollector<IntWritable, Text> out, Reporter reporter)
      throws IOException {

    JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
    JSONObject obj;
    try {
      String rec = arg1.toString();
      obj = (JSONObject) parser.parse(rec);

      short owner = ((Long) obj.get("owner")).shortValue();
      out.collect(new IntWritable(owner), new Text(rec));
      JSONArray mirrors = (JSONArray) obj.get("mirrors");
      for (int j = 0; j < mirrors.size(); j++) {
        out.collect(new IntWritable(((Long) mirrors.get(j)).intValue()),
            new Text(rec));
      }
    } catch (ParseException e) {
View Full Code Here

    int numOwnVertices = 0;

    JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
    while (value.hasNext()) {
      Text vrecString = value.next();
      JSONObject obj;
      try {
        obj = (JSONObject) parser.parse(vrecString.toString());
        int owner = ((Long) obj.get("owner")).intValue();
        if (owner == key.get()) {
          numOwnVertices++;
          reporter.incrCounter(COUNTER.OWN_VERTICES, 1);
        }
        out.collect(new Text("partition" + key.get() + " vrecord"), vrecString);
        numVertices++;
        reporter.incrCounter(COUNTER.VERTICES, 1);
      } catch (ParseException e) {
        e.printStackTrace();
      } // end try parsing
    } // end while

    JSONObject summary = new JSONObject();
    summary.put("numVertices", numVertices);
    summary.put("numOwnVertices", numOwnVertices);
    out.collect(new Text("partition" + key.get() + " meta"),
        new Text(summary.toJSONString()));
  }
View Full Code Here

    vrec.setInEdges(3);
    vrec.setOutEdges(2);
    String s = vrec.toString();
    JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
    try {
      JSONObject obj = (JSONObject) parser.parse(s);
      // System.out.println(obj.toJSONString());
    } catch (ParseException e) {
      e.printStackTrace();
    }

    s = "{\"mirrors\":[0,1,2,3,4,5,6,7],\"inEdges\":212,\"gvid\":0,\"outEdges\":4,\"owner\":5,\"VertexData\":null}";
    try {
      JSONObject obj = (JSONObject) parser.parse(s);
      // System.out.println(obj.toJSONString());
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of net.minidev.json.JSONObject

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.