us.monoid.web
Class JSONResource

java.lang.Object
  extended by us.monoid.web.Resty
      extended by us.monoid.web.AbstractResource
          extended by us.monoid.web.JSONResource

public class JSONResource
extends AbstractResource

A resource presentation in JSON format. You can ask Resty to parse the JSON into a JSONArray or a JSONObject. The JSONObject is similar to org.json.JSONObject and allows full access to the JSON. You can also access the JSON with a JSONPathQuery to extract only the parts you are interested in.

Author:
beders, RobertFischer

Nested Class Summary
 
Nested classes/interfaces inherited from class us.monoid.web.Resty
Resty.Option, Resty.Proxy, Resty.Timeout
 
Constructor Summary
JSONResource(Resty.Option... options)
           
 
Method Summary
 JSONArray array()
          Parse and return JSON array.
 Object get(JSONPathQuery aQuery)
          Gets the partial JSON object or attribute as specified in the path expression.
 Object get(String path)
          Gets the partial JSON object or attribute as specified in the path expression.
 JSONResource json(JSONPathQuery path)
          Execute the given path query on the json GET the returned URI expecting JSON
 JSONResource json(JSONPathQuery path, Content content)
          Execute the given path query on the json and POST to the returned URI expecting JSON
 JSONObject object()
          Parse and return JSON object.
 TextResource text(JSONPathQuery path)
          Execute the given path query on the json and use the returned string as an URI expecting text/*
 JSONObject toObject()
          Added for compatibility with Scala.
 XMLResource xml(JSONPathQuery path)
          Execute the given path query on the json and GET the returned URI expecting text/*
 XMLResource xml(JSONPathQuery path, Content content)
          Execute the given path query on the json and POST to the returned URI expecting text/*
 
Methods inherited from class us.monoid.web.AbstractResource
getUrlConnection, http, location, status, stream
 
Methods inherited from class us.monoid.web.Resty
alwaysSend, authenticate, authenticate, authenticateForRealm, bytes, bytes, bytes, bytes, content, content, content, data, data, delete, dontSend, enc, form, form, identifyAsMozilla, identifyAsResty, ignoreAllCerts, json, json, json, json, path, put, setOptions, setProxy, text, text, text, text, withHeader, xml, xml, xml, xml, xpath
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONResource

public JSONResource(Resty.Option... options)
Method Detail

array

public JSONArray array()
                throws IOException,
                       JSONException
Parse and return JSON array. Parsing is done only once after which the inputStream is at EOF.

Throws:
IOException
JSONException

object

public JSONObject object()
                  throws IOException,
                         JSONException
Parse and return JSON object. Parsing is done only once after which the inputStrem is at EOF.

Returns:
the JSON object
Throws:
IOException
JSONException

toObject

public JSONObject toObject()
                    throws IOException,
                           JSONException
Added for compatibility with Scala. See Issue #2 at github.

Returns:
the JSONObject presentation
Throws:
IOException
JSONException - if data was no valid JSON

json

public JSONResource json(JSONPathQuery path)
                  throws Exception
Execute the given path query on the json GET the returned URI expecting JSON

Parameters:
path - path to the URI to follow
Returns:
a new resource, as a result of getting it from the server in JSON format
Throws:
Exception
JSONException

json

public JSONResource json(JSONPathQuery path,
                         Content content)
                  throws Exception
Execute the given path query on the json and POST to the returned URI expecting JSON

Parameters:
path - path to the URI to follow
Returns:
a new resource, as a result of getting it from the server in JSON format
Throws:
Exception
JSONException

text

public TextResource text(JSONPathQuery path)
                  throws Exception
Execute the given path query on the json and use the returned string as an URI expecting text/*

Parameters:
path - path to the URI to follow
Returns:
a new resource, as a result of getting it from the server in text/plain format
Throws:
Exception
JSONException

xml

public XMLResource xml(JSONPathQuery path)
                throws Exception
Execute the given path query on the json and GET the returned URI expecting text/*

Parameters:
path - path to the URI to follow
Returns:
a new resource, as a result of getting it from the server in JSON format
Throws:
Exception

xml

public XMLResource xml(JSONPathQuery path,
                       Content content)
                throws Exception
Execute the given path query on the json and POST to the returned URI expecting text/*

Parameters:
path - path to the URI to follow
Returns:
a new resource, as a result of getting it from the server in JSON format
Throws:
Exception

get

public Object get(String path)
           throws Exception
Gets the partial JSON object or attribute as specified in the path expression.

Throws:
Exception

get

public Object get(JSONPathQuery aQuery)
           throws Exception
Gets the partial JSON object or attribute as specified in the path expression.

Throws:
Exception


Copyright © 2013. All Rights Reserved.