org.eel.kitchen.jsonschema.ref
Class JsonRef

java.lang.Object
  extended by org.eel.kitchen.jsonschema.ref.JsonRef

public final class JsonRef
extends Object

Representation of a JSON Reference

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:


Method Summary
 boolean equals(Object obj)
           
static JsonRef fromNode(JsonNode node, String key)
          Build a JSON Reference.
 String getFragment()
          Return this ref's fragment part as a string
 URI getLocator()
          Return the absolute part of the underlying URI, without the fragment
 boolean hasFragment()
           
 int hashCode()
           
 boolean isAbsolute()
           
 boolean isEmpty()
           
 JsonRef resolve(JsonRef other)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

fromNode

public static JsonRef fromNode(JsonNode node,
                               String key)
                        throws JsonSchemaException
Build a JSON Reference.

Note that in the event where there is no member by the requested name, an empty JSON Reference is returned.

Parameters:
node - the JSON instance to extract the reference from
key - the member to extract the reference from
Returns:
the reference
Throws:
JsonSchemaException - the key is malformed (not a string, or not an URI)

isEmpty

public boolean isEmpty()

isAbsolute

public boolean isAbsolute()

resolve

public JsonRef resolve(JsonRef other)

getLocator

public URI getLocator()
Return the absolute part of the underlying URI, without the fragment

Returns:
an URI

getFragment

public String getFragment()
Return this ref's fragment part as a string

If there is no fragment, an empty string is returned.

Returns:
the fragment

hasFragment

public boolean hasFragment()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012. All Rights Reserved.