com.github.fge.jackson
Class JsonLoader

java.lang.Object
  extended by com.github.fge.jackson.JsonLoader

public final class JsonLoader
extends Object

Utility class to load JSON values from various sources as JsonNodes.

This class uses a JsonNodeReader to parse JSON inputs.

See Also:
JsonNodeReader

Method Summary
static JsonNode fromFile(File file)
          Same as fromPath(String), but this time the user supplies the File object instead
static JsonNode fromPath(String path)
          Read a JsonNode from a file on the local filesystem.
static JsonNode fromReader(Reader reader)
          Read a JsonNode from a user supplied Reader
static JsonNode fromResource(String resource)
          Read a JsonNode from a resource path.
static JsonNode fromString(String json)
          Read a JsonNode from a string input
static JsonNode fromURL(URL url)
          Read a JsonNode from an URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fromResource

public static JsonNode fromResource(String resource)
                             throws IOException
Read a JsonNode from a resource path.

This method explicitly throws an IOException if the resource does not exist, instead of letting a NullPointerException slip through.

Parameters:
resource - The path to the resource
Returns:
the JSON document at the resource
Throws:
IOException - if the resource does not exist or there was a problem loading it, or if the JSON document is invalid

fromURL

public static JsonNode fromURL(URL url)
                        throws IOException
Read a JsonNode from an URL.

Parameters:
url - The URL to fetch the JSON document from
Returns:
The document at that URL
Throws:
IOException - in case of network problems etc.

fromPath

public static JsonNode fromPath(String path)
                         throws IOException
Read a JsonNode from a file on the local filesystem.

Parameters:
path - the path (relative or absolute) to the file
Returns:
the document in the file
Throws:
IOException - if this is not a file, if it cannot be read, etc.

fromFile

public static JsonNode fromFile(File file)
                         throws IOException
Same as fromPath(String), but this time the user supplies the File object instead

Parameters:
file - the File object
Returns:
The document
Throws:
IOException - in many cases!

fromReader

public static JsonNode fromReader(Reader reader)
                           throws IOException
Read a JsonNode from a user supplied Reader

Parameters:
reader - The reader
Returns:
the document
Throws:
IOException - if the reader has problems

fromString

public static JsonNode fromString(String json)
                           throws IOException
Read a JsonNode from a string input

Parameters:
json - the JSON as a string
Returns:
the document
Throws:
IOException - could not read from string