public final class JsonRef extends Object
JSON Reference, currently a draft, is a way to define a path within a JSON document.
To quote the draft, "A JSON Reference is a JSON object, which contains a member named "$ref", which has a JSON string value." This string value must be a URI. Example:
{
"$ref": "http://example.com/example.json#/foo/bar"
}
This class is used in a more general way than the draft. It is also used as a backing class for schema identifiers.
The implementation is a wrapper over Java's URI, with the
following differences:
This class is thread safe and immutable.
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(JsonRef other)
Tell whether the current JSON Reference contains another
|
static JsonRef |
emptyRef()
Return an empty reference
|
boolean |
equals(Object obj) |
static JsonRef |
fromNode(JsonNode node)
Build a JSON Reference from a
JsonNode |
static JsonRef |
fromString(String s)
Build a JSON Reference from a string input
|
static JsonRef |
fromURI(URI uri)
Build a JSON Reference from a URI
|
JsonFragment |
getFragment()
Return this JSON Reference's fragment
|
URI |
getRootAsURI()
Return this JSON Reference's locator
|
int |
hashCode() |
boolean |
isAbsolute()
Tell whether this reference is an absolute reference
|
JsonRef |
resolve(JsonRef other)
Resolve this reference against another reference
|
String |
toString() |
public static JsonRef fromURI(URI uri)
uri - the provided URINullPointerException - the provided URI is nullJsonRef(URI)public static JsonRef fromString(String s) throws JsonSchemaException
s - the stringJsonSchemaException - string is not a valid URINullPointerException - provided string is nullpublic static JsonRef fromNode(JsonNode node) throws JsonSchemaException
JsonNode
If the node is not textual, this returns an empty reference.
Otherwise, it calls fromString(String) with this node's text
value.
node - the nodeJsonSchemaException - see fromString(String)NullPointerException - provided node is nullpublic static JsonRef emptyRef()
An empty reference is a reference which only has an empty fragment.
public boolean isAbsolute()
A JSON Reference is considered absolute iif the underlying URI is itself absolute and it has an empty, or no, fragment part.
public JsonRef resolve(JsonRef other)
Note: jar URIs need to be special cased, see resolveJarURI(JsonRef).
other - the reference to resolvepublic URI getRootAsURI()
The locator of a fragment is the URI with an empty fragment.
public JsonFragment getFragment()
public boolean contains(JsonRef other)
This is considered true iif both references have the same locator, in other words, if they differ only by their fragment part.
other - the other referenceCopyright © 2012. All Rights Reserved.