Package net.sf.saxon.ma.json
Class JsonHandler
java.lang.Object
net.sf.saxon.ma.json.JsonHandler
- Direct Known Subclasses:
JsonHandlerMap
,JsonHandlerXML
Default handler class for accepting the result from parsing JSON strings
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
endArray()
Close the current arrayvoid
endMap()
Close the current object/mapprotected void
handleInvalidCharacters
(StringBuilder buffer) Deal with invalid characters in the JSON stringprotected void
markAsEscaped
(String escaped, boolean isKey) Optionally apply escaping or unescaping to a value.void
setContext
(XPathContext context) void
setFallbackFunction
(Map<String, GroundedValue> options, XPathContext context) boolean
Set the key to be written for the next entry in an object/mapvoid
Open a new arrayvoid
startMap()
Start a new object/mapvoid
writeBoolean
(boolean value) Write a boolean valuevoid
Write a null valuevoid
writeNumeric
(String asString, AtomicValue parsedValue) Write a numeric valuevoid
writeString
(String val) Write a string value
-
Field Details
-
escape
public boolean escape -
charChecker
-
-
Constructor Details
-
JsonHandler
public JsonHandler()
-
-
Method Details
-
setContext
-
getContext
-
getResult
- Throws:
XPathException
-
setKey
Set the key to be written for the next entry in an object/map- Parameters:
unEscaped
- the key for the entry (null implies no key) in unescaped form (backslashes, if present, do not signal an escape sequence)reEscaped
- the key for the entry (null implies no key) in reescaped form. In this form special characters are represented as backslash-escaped sequences if the escape option is yes; if escape=no, the reEscaped form is the same as the unEscaped form.- Returns:
- true if the key is already present in the map, false if it is not
-
startArray
Open a new array- Throws:
XPathException
- if any error occurs
-
endArray
Close the current array- Throws:
XPathException
- if any error occurs
-
startMap
Start a new object/map- Throws:
XPathException
- if any error occurs
-
endMap
Close the current object/map- Throws:
XPathException
- if any error occurs
-
writeNumeric
Write a numeric value- Parameters:
asString
- the raw string representation of the valueparsedValue
- the parsed representation of the value, typically an xs:double, but under user control- Throws:
XPathException
- if any error occurs
-
writeString
Write a string value- Parameters:
val
- The string to be written (which may or may not contain JSON escape sequences, according to the options that were set)- Throws:
XPathException
- if any error occurs
-
reEscape
Optionally apply escaping or unescaping to a value.- Parameters:
val
- the string to be escaped or unEscaped. This is supplied as a String rather than a UnicodeString because there are special rules for handling unpaired surrogates, which cannot be represented in a UnicodeString- Returns:
- the escaped or unescaped string
- Throws:
XPathException
- if there are invalid characters or escape sequences
-
writeBoolean
Write a boolean value- Parameters:
value
- the boolean value to be written- Throws:
XPathException
- if any error occurs
-
writeNull
Write a null value- Throws:
XPathException
- if any error occurs
-
handleInvalidCharacters
Deal with invalid characters in the JSON string- Parameters:
buffer
- the JSON string- Throws:
XPathException
- if any error occurs
-
markAsEscaped
- Throws:
XPathException
-
setFallbackFunction
public void setFallbackFunction(Map<String, GroundedValue> options, XPathContext context) throws XPathException- Throws:
XPathException
-