public final class JsonRef extends Object
JSON Reference, currently a draft, is a way to address a JSON instance of whatever type.
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"
}
Here we choose to derive a little from the specification and calculate
references from any field, not just $ref. This class is also used,
for instance, to compute id.
The implementation is a wrapper over Java's URI,
with the following differences:
| Modifier and Type | Field and Description |
|---|---|
private static JsonRef |
EMPTY
An empty JSON Reference
|
private static URI |
EMPTY_URI
Empty URI
|
private JsonFragment |
fragment
The fragment of this JSON Reference
|
private static URI |
HASHONLY_URI
URI with only an empty fragment part
|
private URI |
locator
The locator for this fragment
|
private URI |
uri
The URI, as provided by the input, with an appended empty fragment if
no fragment was provided
|
| Modifier | Constructor and Description |
|---|---|
private |
JsonRef(URI uri)
The main constructor, which is private by design
|
| 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() |
private static final URI HASHONLY_URI
private static final URI EMPTY_URI
private static final JsonRef EMPTY
private final URI uri
private final URI locator
private final JsonFragment fragment
private JsonRef(URI uri)
If the provided URI has no fragment, then an empty one is appended.
uri - Input URIpublic 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)
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.