Package us.monoid.json

Examples of us.monoid.json.JSONObject


   * @throws JSONException
   */
  @Test
  public void testJSONPathCompiler() throws ParseException, JSONException {
    System.out.println(this.getClass().getResource("books.json"));
    JSONObject json = read(this.getClass().getResource("books.json"));
    JSONPathExpr evaluator = parse("store.book[0].author");
    Object result = evaluator.eval(json);
    System.out.println(result);
    assertEquals("Nigel Rees", result);
   
View Full Code Here


    return x;
  }

  JSONObject read(URL testFile) {
    try {
      return new JSONObject(new JSONTokener(new InputStreamReader(testFile.openStream(), "UTF-8")));
    } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (JSONException e) {
      // TODO Auto-generated catch block
View Full Code Here

    return json;
  }
 
  /** Transforming the JSON on the fly */
  protected JSONObject unmarshal() throws IOException, JSONException {
    JSONObject json = new JSONObject(new JSONTokener(new InputStreamReader(inputStream, "UTF-8")));
    return json;
  }
View Full Code Here

    expr = anExpression;
  }
 
  @Override
  Object eval(JSONResource resource) throws JSONException, ParseException, IOException {
    JSONObject json = resource.object();
    Object result = getCompiler().expr().eval(json);
    return result;
  }
View Full Code Here

    TextResource text = r.text("http://localhost:9998/mime/multipart",
        form(data("bubu", "lala"), data("schön", "böööh")));
    String result = text.toString();
    System.out.println(result);
    assertTrue(result.contains("bubu") && result.contains("=?ISO-8859-1?Q?sch=F6n?="));
    JSONObject json = new JSONObject();
    json.put("bubu", "lala");
    text = r.text("http://localhost:9998/mime/multipart", form(data("someJson", content(json)), data("someText", "Text")));
    result = text.toString();
    System.out.println(result);
    assertTrue(result.contains("someJson") && result.contains("application/json") && result.contains("someText"));
  }
View Full Code Here

    String authorizationCode = getAuthorizationCode(req);
    Resty resty = createResty();

    String tokenUri = getTokenUri();

    JSONObject json = new JSONObject();
    try {
      json.put("client_id", properties.get("auth0.client_id"));
      json.put("client_secret", properties.get("auth0.client_secret"));
      json.put("redirect_uri", req.getRequestURL().toString());
      json.put("grant_type", "authorization_code");
      json.put("code", authorizationCode);

      JSONResource tokenInfo = resty.json(tokenUri, content(json));
      return new Tokens(tokenInfo.toObject());

    } catch (Exception ex) {
View Full Code Here

    expr = anExpression;
  }
 
  @Override
  Object eval(JSONResource resource) throws JSONException, ParseException, IOException {
    JSONObject json = resource.object();
    log.fine("JSON Received:" + json);
    Object result = getCompiler().json().eval(json);
    return result;
  }
View Full Code Here

    }
  }
 
  protected void testGeo() throws Exception {
    System.out.println(this.getClass().getResource("geo.json"));
    JSONObject json = read(this.getClass().getResource("geo.json"));
    System.out.println(json);
    JSONPathExpr evaluator = parse("results[address_components.short_name='U.S. 101'].formatted_address");
    Object result = evaluator.eval(json);
    System.out.println(result);
    assertTrue(result.toString().contains("Golden Gate Bridge"));
View Full Code Here

  }

  @Test
  public void testSimplePath() throws Exception {
    System.out.println(this.getClass().getResource("books.json"));
    JSONObject json = read(this.getClass().getResource("books.json"));

    JSONPathExpr evaluator = parse("store.book.reviewed-by");
    Object result = evaluator.eval(json);
    System.out.println(result);
    assertTrue(result instanceof List);
View Full Code Here

   * @throws JSONException
   */
  @Test
  public void testJSONPathCompiler() throws ParseException, JSONException {
    System.out.println(this.getClass().getResource("books.json"));
    JSONObject json = read(this.getClass().getResource("books.json"));
    JSONPathExpr evaluator = parse("store.book[0].author");
    Object result = evaluator.eval(json);
    System.out.println(result);
    assertEquals("Nigel Rees", result);
   
View Full Code Here

TOP

Related Classes of us.monoid.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.