|
1 | 1 | package io.burt.jmespath; |
2 | 2 |
|
3 | 3 | import java.util.List; |
4 | | -import java.util.Iterator; |
5 | 4 | import java.util.Collection; |
6 | 5 |
|
7 | 6 | import io.burt.jmespath.parser.ExpressionParser; |
|
10 | 9 | import io.burt.jmespath.function.ArgumentTypeException; |
11 | 10 | import io.burt.jmespath.node.NodeFactory; |
12 | 11 | import io.burt.jmespath.node.StandardNodeFactory; |
13 | | -import io.burt.jmespath.util.StringEscapeHelper; |
14 | 12 |
|
15 | 13 | /** |
16 | 14 | * This class can be extended instead of implementing {@link Adapter} directly, |
|
20 | 18 | * these methods if they have more efficient means to perform the same job. |
21 | 19 | */ |
22 | 20 | public abstract class BaseRuntime<T> implements Adapter<T> { |
23 | | - private static final StringEscapeHelper jsonEscapeHelper = new StringEscapeHelper( |
24 | | - true, |
25 | | - 'b', '\b', |
26 | | - 't', '\t', |
27 | | - 'n', '\n', |
28 | | - 'f', '\f', |
29 | | - 'r', '\r', |
30 | | - '\\', '\\', |
31 | | - '\"', '\"' |
32 | | - ); |
33 | 21 |
|
34 | 22 | private final FunctionRegistry functionRegistry; |
35 | 23 | private final NodeFactory<T> nodeFactory; |
@@ -173,82 +161,6 @@ public int hashCode() { |
173 | 161 | return 31; |
174 | 162 | } |
175 | 163 |
|
176 | | - /** |
177 | | - * Helper method to render a value as JSON. |
178 | | - * |
179 | | - * Assumes that <code>null</code>, <code>number</code> and <code>boolean</code> |
180 | | - * render themseves correctly with <code>toString</code>, and that |
181 | | - * <code>string</code> renders itself as an unquoted string. |
182 | | - */ |
183 | | - protected String unparse(T object) { |
184 | | - switch (typeOf(object)) { |
185 | | - case NUMBER: |
186 | | - return unparseNumber(object); |
187 | | - case BOOLEAN: |
188 | | - return unparseBoolean(object); |
189 | | - case NULL: |
190 | | - return unparseNull(object); |
191 | | - case STRING: |
192 | | - return unparseString(object); |
193 | | - case OBJECT: |
194 | | - return unparseObject(object); |
195 | | - case ARRAY: |
196 | | - return unparseArray(object); |
197 | | - default: |
198 | | - throw new IllegalStateException(); |
199 | | - } |
200 | | - } |
201 | | - |
202 | | - protected String unparseNumber(T object) { |
203 | | - return object.toString(); |
204 | | - } |
205 | | - |
206 | | - protected String unparseBoolean(T object) { |
207 | | - return object.toString(); |
208 | | - } |
209 | | - |
210 | | - protected String unparseNull(T object) { |
211 | | - return "null"; |
212 | | - } |
213 | | - |
214 | | - protected String unparseString(T object) { |
215 | | - return String.format("\"%s\"", escapeString(toString(object))); |
216 | | - } |
217 | | - |
218 | | - protected String escapeString(String str) { |
219 | | - return jsonEscapeHelper.escape(str); |
220 | | - } |
221 | | - |
222 | | - protected String unparseObject(T object) { |
223 | | - StringBuilder str = new StringBuilder("{"); |
224 | | - Iterator<T> keys = getPropertyNames(object).iterator(); |
225 | | - while (keys.hasNext()) { |
226 | | - T key = keys.next(); |
227 | | - T value = getProperty(object, key); |
228 | | - str.append(unparseString(key)); |
229 | | - str.append(':'); |
230 | | - str.append(unparse(value)); |
231 | | - if (keys.hasNext()) { |
232 | | - str.append(','); |
233 | | - } |
234 | | - } |
235 | | - str.append('}'); |
236 | | - return str.toString(); |
237 | | - } |
238 | | - |
239 | | - protected String unparseArray(T array) { |
240 | | - StringBuilder str = new StringBuilder("["); |
241 | | - Iterator<T> elements = toList(array).iterator(); |
242 | | - while (elements.hasNext()) { |
243 | | - str.append(unparse(elements.next())); |
244 | | - if (elements.hasNext()) { |
245 | | - str.append(','); |
246 | | - } |
247 | | - } |
248 | | - str.append(']'); |
249 | | - return str.toString(); |
250 | | - } |
251 | | - |
252 | 164 | @Override |
253 | 165 | @Deprecated |
254 | 166 | public T getProperty(T value, String name) { |
|
0 commit comments