org.basex.query.util.json
Class JsonMapConverter

java.lang.Object
  extended by org.basex.query.util.json.JsonConverter
      extended by org.basex.query.util.json.JsonMapConverter
All Implemented Interfaces:
JsonHandler

public final class JsonMapConverter
extends JsonConverter
implements JsonHandler

Provides a method for parsing a JSON string and converting it to an XQuery item made of nested maps.

The mapping from JSON to XQuery is the following:

string
xs:string
number
xs:double
boolean
xs:boolean
null
an empty sequence ()
array (e.g. ["foo", true, 123])
an XQuery map with integer keys, starting by 1 (e.g. map{1:='foo', 2:=true(), 3:=123})
object (e.g. {"foo": 42, "bar": null})
an XQuery map (e.g. map{'foo':=42, 'bar':=()})

Author:
BaseX Team 2005-12, BSD License, Leo Woerteler

Field Summary
 
Fields inherited from class org.basex.query.util.json.JsonConverter
COMPACT, info, JSONML, MAPS
 
Constructor Summary
JsonMapConverter(JsonParser.Spec sp, boolean unesc, InputInfo ii)
          Constructor.
 
Method Summary
 void booleanLit(boolean b)
          Called when a boolean literal is encountered.
 void closeArg()
          Called when an argument of a constructor function is closed.
 void closeArray()
          Called when a JSON array is closed.
 void closeArrayEntry()
          Called when an entry of a JSON array is closed.
 void closeConstr()
          Called when a constructor function is closed.
 void closeEntry()
          Called when an entry of a JSON object is closed.
 void closeObject()
          Called when a JSON object is closed.
 Item convert(java.lang.String in)
          Converts the given JSON string into an XQuery value.
 void nullLit()
          Called when a null literal is encountered.
 void numberLit(byte[] val)
          Called when a number literal is encountered.
 void openArg()
          Called when an argument of a constructor function is opened.
 void openArray()
          Called when a JSON array is opened.
 void openArrayEntry()
          Called when an entry of a JSON array is opened.
 void openConstr(byte[] name)
          Called when a constructor function is opened.
 void openEntry(byte[] key)
          Called when an entry of a JSON object is opened.
 void openObject()
          Called when a JSON object is opened.
 void stringLit(byte[] value)
          Called when a string literal is encountered.
 
Methods inherited from class org.basex.query.util.json.JsonConverter
newInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonMapConverter

public JsonMapConverter(JsonParser.Spec sp,
                        boolean unesc,
                        InputInfo ii)
Constructor.

Parameters:
sp - JSON spec
unesc - unescape flag
ii - input info
Method Detail

convert

public Item convert(java.lang.String in)
             throws QueryException
Description copied from class: JsonConverter
Converts the given JSON string into an XQuery value.

Specified by:
convert in class JsonConverter
Parameters:
in - the JSON string
Returns:
the result
Throws:
QueryException - parse exception

openObject

public void openObject()
Description copied from interface: JsonHandler
Called when a JSON object is opened.

Specified by:
openObject in interface JsonHandler

openEntry

public void openEntry(byte[] key)
Description copied from interface: JsonHandler
Called when an entry of a JSON object is opened.

Specified by:
openEntry in interface JsonHandler
Parameters:
key - the key of the entry

closeEntry

public void closeEntry()
                throws QueryException
Description copied from interface: JsonHandler
Called when an entry of a JSON object is closed.

Specified by:
closeEntry in interface JsonHandler
Throws:
QueryException - query exception

closeObject

public void closeObject()
Description copied from interface: JsonHandler
Called when a JSON object is closed.

Specified by:
closeObject in interface JsonHandler

openArray

public void openArray()
Description copied from interface: JsonHandler
Called when a JSON array is opened.

Specified by:
openArray in interface JsonHandler

openArrayEntry

public void openArrayEntry()
Description copied from interface: JsonHandler
Called when an entry of a JSON array is opened.

Specified by:
openArrayEntry in interface JsonHandler

closeArrayEntry

public void closeArrayEntry()
                     throws QueryException
Description copied from interface: JsonHandler
Called when an entry of a JSON array is closed.

Specified by:
closeArrayEntry in interface JsonHandler
Throws:
QueryException - query exception

closeArray

public void closeArray()
Description copied from interface: JsonHandler
Called when a JSON array is closed.

Specified by:
closeArray in interface JsonHandler

openConstr

public void openConstr(byte[] name)
Description copied from interface: JsonHandler
Called when a constructor function is opened.

Specified by:
openConstr in interface JsonHandler
Parameters:
name - name of the constructor

openArg

public void openArg()
Description copied from interface: JsonHandler
Called when an argument of a constructor function is opened.

Specified by:
openArg in interface JsonHandler

closeArg

public void closeArg()
              throws QueryException
Description copied from interface: JsonHandler
Called when an argument of a constructor function is closed.

Specified by:
closeArg in interface JsonHandler
Throws:
QueryException - query exception

closeConstr

public void closeConstr()
                 throws QueryException
Description copied from interface: JsonHandler
Called when a constructor function is closed.

Specified by:
closeConstr in interface JsonHandler
Throws:
QueryException - query exception

numberLit

public void numberLit(byte[] val)
               throws QueryException
Description copied from interface: JsonHandler
Called when a number literal is encountered.

Specified by:
numberLit in interface JsonHandler
Parameters:
val - string representation of the number literal
Throws:
QueryException - query exception

stringLit

public void stringLit(byte[] value)
Description copied from interface: JsonHandler
Called when a string literal is encountered.

Specified by:
stringLit in interface JsonHandler
Parameters:
value - the string

nullLit

public void nullLit()
Description copied from interface: JsonHandler
Called when a null literal is encountered.

Specified by:
nullLit in interface JsonHandler

booleanLit

public void booleanLit(boolean b)
Description copied from interface: JsonHandler
Called when a boolean literal is encountered.

Specified by:
booleanLit in interface JsonHandler
Parameters:
b - the boolean