{
57 |
58 | JsonParser parser;
59 |
60 | /**
61 | * Returns the current parser location.
62 | *
63 | * @return the current parser location
64 | */
65 | protected Location getLocation() {
66 | return parser.getLocation();
67 | }
68 |
69 | /**
70 | * Indicates the beginning of a null
literal in the JSON input. This method will be
71 | * called when reading the first character of the literal.
72 | */
73 | public void startNull() {
74 | }
75 |
76 | /**
77 | * Indicates the end of a null
literal in the JSON input. This method will be called
78 | * after reading the last character of the literal.
79 | */
80 | public void endNull() {
81 | }
82 |
83 | /**
84 | * Indicates the beginning of a boolean literal (true
or false
) in the
85 | * JSON input. This method will be called when reading the first character of the literal.
86 | */
87 | public void startBoolean() {
88 | }
89 |
90 | /**
91 | * Indicates the end of a boolean literal (true
or false
) in the JSON
92 | * input. This method will be called after reading the last character of the literal.
93 | *
94 | * @param value
95 | * the parsed boolean value
96 | */
97 | public void endBoolean(boolean value) {
98 | }
99 |
100 | /**
101 | * Indicates the beginning of a string in the JSON input. This method will be called when reading
102 | * the opening double quote character ('"'
).
103 | */
104 | public void startString() {
105 | }
106 |
107 | /**
108 | * Indicates the end of a string in the JSON input. This method will be called after reading the
109 | * closing double quote character ('"'
).
110 | *
111 | * @param string
112 | * the parsed string
113 | */
114 | public void endString(String string) {
115 | }
116 |
117 | /**
118 | * Indicates the beginning of a number in the JSON input. This method will be called when reading
119 | * the first character of the number.
120 | */
121 | public void startNumber() {
122 | }
123 |
124 | /**
125 | * Indicates the end of a number in the JSON input. This method will be called after reading the
126 | * last character of the number.
127 | *
128 | * @param string
129 | * the parsed number string
130 | */
131 | public void endNumber(String string) {
132 | }
133 |
134 | /**
135 | * Indicates the beginning of an array in the JSON input. This method will be called when reading
136 | * the opening square bracket character ('['
).
137 | *
138 | * This method may return an object to handle subsequent parser events for this array. This array
139 | * handler will then be provided in all calls to {@link #startArrayValue(Object)
140 | * startArrayValue()}, {@link #endArrayValue(Object) endArrayValue()}, and
141 | * {@link #endArray(Object) endArray()} for this array.
142 | *
143 | *
144 | * @return a handler for this array, or null
if not needed
145 | */
146 | public A startArray() {
147 | return null;
148 | }
149 |
150 | /**
151 | * Indicates the end of an array in the JSON input. This method will be called after reading the
152 | * closing square bracket character (']'
).
153 | *
154 | * @param array
155 | * the array handler returned from {@link #startArray()}, or null
if not
156 | * provided
157 | */
158 | public void endArray(A array) {
159 | }
160 |
161 | /**
162 | * Indicates the beginning of an array element in the JSON input. This method will be called when
163 | * reading the first character of the element, just before the call to the start
164 | * method for the specific element type ({@link #startString()}, {@link #startNumber()}, etc.).
165 | *
166 | * @param array
167 | * the array handler returned from {@link #startArray()}, or null
if not
168 | * provided
169 | */
170 | public void startArrayValue(A array) {
171 | }
172 |
173 | /**
174 | * Indicates the end of an array element in the JSON input. This method will be called after
175 | * reading the last character of the element value, just after the end
method for the
176 | * specific element type (like {@link #endString(String) endString()}, {@link #endNumber(String)
177 | * endNumber()}, etc.).
178 | *
179 | * @param array
180 | * the array handler returned from {@link #startArray()}, or null
if not
181 | * provided
182 | */
183 | public void endArrayValue(A array) {
184 | }
185 |
186 | /**
187 | * Indicates the beginning of an object in the JSON input. This method will be called when reading
188 | * the opening curly bracket character ('{'
).
189 | *
190 | * This method may return an object to handle subsequent parser events for this object. This
191 | * object handler will be provided in all calls to {@link #startObjectName(Object)
192 | * startObjectName()}, {@link #endObjectName(Object, String) endObjectName()},
193 | * {@link #startObjectValue(Object, String) startObjectValue()},
194 | * {@link #endObjectValue(Object, String) endObjectValue()}, and {@link #endObject(Object)
195 | * endObject()} for this object.
196 | *
197 | *
198 | * @return a handler for this object, or null
if not needed
199 | */
200 | public O startObject() {
201 | return null;
202 | }
203 |
204 | /**
205 | * Indicates the end of an object in the JSON input. This method will be called after reading the
206 | * closing curly bracket character ('}'
).
207 | *
208 | * @param object
209 | * the object handler returned from {@link #startObject()}, or null if not provided
210 | */
211 | public void endObject(O object) {
212 | }
213 |
214 | /**
215 | * Indicates the beginning of the name of an object member in the JSON input. This method will be
216 | * called when reading the opening quote character ('"') of the member name.
217 | *
218 | * @param object
219 | * the object handler returned from {@link #startObject()}, or null
if not
220 | * provided
221 | */
222 | public void startObjectName(O object) {
223 | }
224 |
225 | /**
226 | * Indicates the end of an object member name in the JSON input. This method will be called after
227 | * reading the closing quote character ('"'
) of the member name.
228 | *
229 | * @param object
230 | * the object handler returned from {@link #startObject()}, or null if not provided
231 | * @param name
232 | * the parsed member name
233 | */
234 | public void endObjectName(O object, String name) {
235 | }
236 |
237 | /**
238 | * Indicates the beginning of the name of an object member in the JSON input. This method will be
239 | * called when reading the opening quote character ('"') of the member name.
240 | *
241 | * @param object
242 | * the object handler returned from {@link #startObject()}, or null
if not
243 | * provided
244 | * @param name
245 | * the member name
246 | */
247 | public void startObjectValue(O object, String name) {
248 | }
249 |
250 | /**
251 | * Indicates the end of an object member value in the JSON input. This method will be called after
252 | * reading the last character of the member value, just after the end
method for the
253 | * specific member type (like {@link #endString(String) endString()}, {@link #endNumber(String)
254 | * endNumber()}, etc.).
255 | *
256 | * @param object
257 | * the object handler returned from {@link #startObject()}, or null if not provided
258 | * @param name
259 | * the parsed member name
260 | */
261 | public void endObjectValue(O object, String name) {
262 | }
263 |
264 | }
--------------------------------------------------------------------------------
/src/main/java/com/dashjoin/jsonata/json/JsonParser.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013, 2016 EclipseSource.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in all
12 | * copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | * SOFTWARE.
21 | ******************************************************************************/
22 | package com.dashjoin.jsonata.json;
23 | //package com.eclipsesource.json;
24 |
25 | import java.io.IOException;
26 | import java.io.Reader;
27 | import java.io.StringReader;
28 |
29 |
30 | /**
31 | * A streaming parser for JSON text. The parser reports all events to a given handler.
32 | */
33 | public class JsonParser {
34 |
35 | private static final int MAX_NESTING_LEVEL = 1000;
36 | private static final int MIN_BUFFER_SIZE = 10;
37 | private static final int DEFAULT_BUFFER_SIZE = 1024;
38 |
39 | private final JsonHandler