-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompression.diff
More file actions
401 lines (390 loc) · 14.9 KB
/
Copy pathcompression.diff
File metadata and controls
401 lines (390 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
--- input/input.java
+++ output/output.java
@@ -253,27 +253,8 @@
public Gson() {
this(
Excluder.DEFAULT,
- DEFAULT_FIELD_NAMING_STRATEGY,
- Collections.<Type, InstanceCreator<?>>emptyMap(),
- DEFAULT_SERIALIZE_NULLS,
- DEFAULT_COMPLEX_MAP_KEYS,
- DEFAULT_JSON_NON_EXECUTABLE,
- DEFAULT_ESCAPE_HTML,
- DEFAULT_FORMATTING_STYLE,
- DEFAULT_STRICTNESS,
- DEFAULT_SPECIALIZE_FLOAT_VALUES,
- DEFAULT_USE_JDK_UNSAFE,
- LongSerializationPolicy.DEFAULT,
- DEFAULT_DATE_PATTERN,
- DateFormat.DEFAULT,
- DateFormat.DEFAULT,
- Collections.<TypeAdapterFactory>emptyList(),
- Collections.<TypeAdapterFactory>emptyList(),
- Collections.<TypeAdapterFactory>emptyList(),
- DEFAULT_OBJECT_TO_NUMBER_STRATEGY,
- DEFAULT_NUMBER_TO_NUMBER_STRATEGY,
+ { … 19 line(s) … ⟦tj:fe630fc502de9c08ebe261135c8ba729⟧ }
Collections.<ReflectionAccessFilter>emptyList());
- }
Gson(
Excluder excluder,
@@ -299,104 +280,8 @@
List<ReflectionAccessFilter> reflectionFilters) {
this.excluder = excluder;
this.fieldNamingStrategy = fieldNamingStrategy;
- this.instanceCreators = instanceCreators;
- this.constructorConstructor =
- new ConstructorConstructor(instanceCreators, useJdkUnsafe, reflectionFilters);
- this.serializeNulls = serializeNulls;
- this.complexMapKeySerialization = complexMapKeySerialization;
- this.generateNonExecutableJson = generateNonExecutableGson;
- this.htmlSafe = htmlSafe;
- this.formattingStyle = formattingStyle;
- this.strictness = strictness;
- this.serializeSpecialFloatingPointValues = serializeSpecialFloatingPointValues;
- this.useJdkUnsafe = useJdkUnsafe;
- this.longSerializationPolicy = longSerializationPolicy;
- this.datePattern = datePattern;
- this.dateStyle = dateStyle;
- this.timeStyle = timeStyle;
- this.builderFactories = builderFactories;
- this.builderHierarchyFactories = builderHierarchyFactories;
- this.objectToNumberStrategy = objectToNumberStrategy;
- this.numberToNumberStrategy = numberToNumberStrategy;
- this.reflectionFilters = reflectionFilters;
-
- List<TypeAdapterFactory> factories = new ArrayList<>();
-
- // built-in type adapters that cannot be overridden
- factories.add(TypeAdapters.JSON_ELEMENT_FACTORY);
- factories.add(ObjectTypeAdapter.getFactory(objectToNumberStrategy));
-
- // the excluder must precede all adapters that handle user-defined types
- factories.add(excluder);
-
- // users' type adapters
- factories.addAll(factoriesToBeAdded);
-
- // type adapters for basic platform types
- factories.add(TypeAdapters.STRING_FACTORY);
- factories.add(TypeAdapters.INTEGER_FACTORY);
- factories.add(TypeAdapters.BOOLEAN_FACTORY);
- factories.add(TypeAdapters.BYTE_FACTORY);
- factories.add(TypeAdapters.SHORT_FACTORY);
- TypeAdapter<Number> longAdapter = longAdapter(longSerializationPolicy);
- factories.add(TypeAdapters.newFactory(long.class, Long.class, longAdapter));
- factories.add(
- TypeAdapters.newFactory(
- double.class, Double.class, doubleAdapter(serializeSpecialFloatingPointValues)));
- factories.add(
- TypeAdapters.newFactory(
- float.class, Float.class, floatAdapter(serializeSpecialFloatingPointValues)));
- factories.add(NumberTypeAdapter.getFactory(numberToNumberStrategy));
- factories.add(TypeAdapters.ATOMIC_INTEGER_FACTORY);
- factories.add(TypeAdapters.ATOMIC_BOOLEAN_FACTORY);
- factories.add(TypeAdapters.newFactory(AtomicLong.class, atomicLongAdapter(longAdapter)));
- factories.add(
- TypeAdapters.newFactory(AtomicLongArray.class, atomicLongArrayAdapter(longAdapter)));
- factories.add(TypeAdapters.ATOMIC_INTEGER_ARRAY_FACTORY);
- factories.add(TypeAdapters.CHARACTER_FACTORY);
- factories.add(TypeAdapters.STRING_BUILDER_FACTORY);
- factories.add(TypeAdapters.STRING_BUFFER_FACTORY);
- factories.add(TypeAdapters.newFactory(BigDecimal.class, TypeAdapters.BIG_DECIMAL));
- factories.add(TypeAdapters.newFactory(BigInteger.class, TypeAdapters.BIG_INTEGER));
- // Add adapter for LazilyParsedNumber because user can obtain it from Gson and then try to
- // serialize it again
- factories.add(
- TypeAdapters.newFactory(LazilyParsedNumber.class, TypeAdapters.LAZILY_PARSED_NUMBER));
- factories.add(TypeAdapters.URL_FACTORY);
- factories.add(TypeAdapters.URI_FACTORY);
- factories.add(TypeAdapters.UUID_FACTORY);
- factories.add(TypeAdapters.CURRENCY_FACTORY);
- factories.add(TypeAdapters.LOCALE_FACTORY);
- factories.add(TypeAdapters.INET_ADDRESS_FACTORY);
- factories.add(TypeAdapters.BIT_SET_FACTORY);
- factories.add(DefaultDateTypeAdapter.DEFAULT_STYLE_FACTORY);
- factories.add(TypeAdapters.CALENDAR_FACTORY);
-
- if (SqlTypesSupport.SUPPORTS_SQL_TYPES) {
- factories.add(SqlTypesSupport.TIME_FACTORY);
- factories.add(SqlTypesSupport.DATE_FACTORY);
- factories.add(SqlTypesSupport.TIMESTAMP_FACTORY);
- }
-
- factories.add(ArrayTypeAdapter.FACTORY);
- factories.add(TypeAdapters.CLASS_FACTORY);
-
- // type adapters for composite and user-defined types
- factories.add(new CollectionTypeAdapterFactory(constructorConstructor));
- factories.add(new MapTypeAdapterFactory(constructorConstructor, complexMapKeySerialization));
- this.jsonAdapterFactory = new JsonAdapterAnnotationTypeAdapterFactory(constructorConstructor);
- factories.add(jsonAdapterFactory);
- factories.add(TypeAdapters.ENUM_FACTORY);
- factories.add(
- new ReflectiveTypeAdapterFactory(
- constructorConstructor,
- fieldNamingStrategy,
- excluder,
- jsonAdapterFactory,
- reflectionFilters));
-
+ { … 96 line(s) … ⟦tj:50bd5444bdf44a026688e29bfc99d0d0⟧ }
this.factories = Collections.unmodifiableList(factories);
- }
/**
* Returns a new GsonBuilder containing all custom factories and configuration used by the current
@@ -454,25 +339,9 @@
return new TypeAdapter<Number>() {
@Override
public Double read(JsonReader in) throws IOException {
- if (in.peek() == JsonToken.NULL) {
- in.nextNull();
- return null;
- }
- return in.nextDouble();
- }
-
- @Override
+ { … 8 line(s) … ⟦tj:2893fe49a248731289c4cdc81cd6b445⟧ }
public void write(JsonWriter out, Number value) throws IOException {
- if (value == null) {
- out.nullValue();
- return;
- }
- double doubleValue = value.doubleValue();
- checkValidFloatingPoint(doubleValue);
- out.value(doubleValue);
- }
- };
- }
+ { … 10 line(s) … ⟦tj:4ade93ef8e62bd6b724b459106630521⟧ }
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) {
if (serializeSpecialFloatingPointValues) {
@@ -481,28 +350,12 @@
return new TypeAdapter<Number>() {
@Override
public Float read(JsonReader in) throws IOException {
- if (in.peek() == JsonToken.NULL) {
- in.nextNull();
- return null;
- }
- return (float) in.nextDouble();
- }
-
- @Override
+ { … 8 line(s) … ⟦tj:40fa6e44efdf342f4f7dd91b775118e0⟧ }
public void write(JsonWriter out, Number value) throws IOException {
if (value == null) {
out.nullValue();
- return;
- }
- float floatValue = value.floatValue();
- checkValidFloatingPoint(floatValue);
- // For backward compatibility don't call `JsonWriter.value(float)` because that method has
- // been newly added and not all custom JsonWriter implementations might override it yet
- Number floatNumber = value instanceof Float ? value : floatValue;
- out.value(floatNumber);
- }
+ { … 9 line(s) … ⟦tj:841eac4dbdae552354e484ad75580101⟧ }
};
- }
static void checkValidFloatingPoint(double value) {
if (Double.isNaN(value) || Double.isInfinite(value)) {
@@ -520,14 +373,7 @@
return new TypeAdapter<Number>() {
@Override
public Number read(JsonReader in) throws IOException {
- if (in.peek() == JsonToken.NULL) {
- in.nextNull();
- return null;
- }
- return in.nextLong();
- }
-
- @Override
+ { … 8 line(s) … ⟦tj:c1f5da5f442f5c369202c505d5b3d35a⟧ }
public void write(JsonWriter out, Number value) throws IOException {
if (value == null) {
out.nullValue();
@@ -558,31 +404,12 @@
return new TypeAdapter<AtomicLongArray>() {
@Override
public void write(JsonWriter out, AtomicLongArray value) throws IOException {
- out.beginArray();
- for (int i = 0, length = value.length(); i < length; i++) {
- longAdapter.write(out, value.get(i));
- }
- out.endArray();
- }
-
- @Override
+ { … 8 line(s) … ⟦tj:7213a93948eca5bf831a563b9b049c4e⟧ }
public AtomicLongArray read(JsonReader in) throws IOException {
List<Long> list = new ArrayList<>();
in.beginArray();
- while (in.hasNext()) {
- long value = longAdapter.read(in).longValue();
- list.add(value);
- }
- in.endArray();
- int length = list.size();
- AtomicLongArray array = new AtomicLongArray(length);
- for (int i = 0; i < length; ++i) {
- array.set(i, list.get(i));
- }
- return array;
- }
+ { … 12 line(s) … ⟦tj:205c2fe46842ae867184339275f6ace3⟧ }
}.nullSafe();
- }
/**
* Returns the type adapter for {@code type}.
@@ -598,63 +425,8 @@
public <T> TypeAdapter<T> getAdapter(TypeToken<T> type) {
Objects.requireNonNull(type, "type must not be null");
TypeAdapter<?> cached = typeTokenCache.get(type);
- if (cached != null) {
- @SuppressWarnings("unchecked")
- TypeAdapter<T> adapter = (TypeAdapter<T>) cached;
- return adapter;
- }
-
- Map<TypeToken<?>, TypeAdapter<?>> threadCalls = threadLocalAdapterResults.get();
- boolean isInitialAdapterRequest = false;
- if (threadCalls == null) {
- threadCalls = new HashMap<>();
- threadLocalAdapterResults.set(threadCalls);
- isInitialAdapterRequest = true;
- } else {
- // the key and value type parameters always agree
- @SuppressWarnings("unchecked")
- TypeAdapter<T> ongoingCall = (TypeAdapter<T>) threadCalls.get(type);
- if (ongoingCall != null) {
- return ongoingCall;
- }
- }
-
- TypeAdapter<T> candidate = null;
- try {
- FutureTypeAdapter<T> call = new FutureTypeAdapter<>();
- threadCalls.put(type, call);
-
- for (TypeAdapterFactory factory : factories) {
- candidate = factory.create(this, type);
- if (candidate != null) {
- call.setDelegate(candidate);
- // Replace future adapter with actual adapter
- threadCalls.put(type, candidate);
- break;
- }
- }
- } finally {
- if (isInitialAdapterRequest) {
- threadLocalAdapterResults.remove();
- }
- }
-
- if (candidate == null) {
- throw new IllegalArgumentException(
- "GSON (" + GsonBuildConfig.VERSION + ") cannot handle " + type);
- }
-
- if (isInitialAdapterRequest) {
- /*
- * Publish resolved adapters to all threads
- * Can only do this for the initial request because cyclic dependency TypeA -> TypeB -> TypeA
- * would otherwise publish adapter for TypeB which uses not yet resolved adapter for TypeA
- * See https://github.com/google/gson/issues/625
- */
- typeTokenCache.putAll(threadCalls);
- }
+ { … 55 line(s) … ⟦tj:376b1311ec9f2014451e5855fbd993d5⟧ }
return candidate;
- }
/**
* Returns the type adapter for {@code type}.
@@ -730,33 +502,8 @@
public <T> TypeAdapter<T> getDelegateAdapter(TypeAdapterFactory skipPast, TypeToken<T> type) {
Objects.requireNonNull(skipPast, "skipPast must not be null");
Objects.requireNonNull(type, "type must not be null");
-
- if (jsonAdapterFactory.isClassJsonAdapterFactory(type, skipPast)) {
- skipPast = jsonAdapterFactory;
- }
-
- boolean skipPastFound = false;
- for (TypeAdapterFactory factory : factories) {
- if (!skipPastFound) {
- if (factory == skipPast) {
- skipPastFound = true;
- }
- continue;
- }
-
- TypeAdapter<T> candidate = factory.create(this, type);
- if (candidate != null) {
- return candidate;
- }
- }
-
- if (skipPastFound) {
- throw new IllegalArgumentException("GSON cannot serialize or deserialize " + type);
- } else {
- // Probably a factory from @JsonAdapter on a field
- return getAdapter(type);
+ { … 25 line(s) … ⟦tj:2b32eefa9c60d7274963812e0e947abb⟧ }
}
- }
/**
* This method serializes the specified object into its equivalent representation as a tree of
@@ -1051,16 +798,7 @@
* </ul>
*/
public JsonWriter newJsonWriter(Writer writer) throws IOException {
- if (generateNonExecutableJson) {
- writer.write(JSON_NON_EXECUTABLE_PREFIX);
- }
- JsonWriter jsonWriter = new JsonWriter(writer);
- jsonWriter.setFormattingStyle(formattingStyle);
- jsonWriter.setHtmlSafe(htmlSafe);
- jsonWriter.setStrictness(strictness == null ? Strictness.LEGACY_STRICT : strictness);
- jsonWriter.setSerializeNulls(serializeNulls);
- return jsonWriter;
- }
+ { … 10 line(s) … ⟦tj:0004c0c2a6885ce782d4b2f12af89144⟧ }
/**
* Returns a new JSON reader configured for the settings on this Gson instance.
@@ -1494,17 +1232,7 @@
}
private TypeAdapter<T> delegate() {
- TypeAdapter<T> delegate = this.delegate;
- if (delegate == null) {
- // Can occur when adapter is leaked to other thread or when adapter is used for
- // (de-)serialization
- // directly within the TypeAdapterFactory which requested it
- throw new IllegalStateException(
- "Adapter for type with cyclic dependency has been used"
- + " before dependency has been resolved");
- }
- return delegate;
- }
+ { … 11 line(s) … ⟦tj:26caf9681d2112aef5d36439f4e95422⟧ }
@Override
public TypeAdapter<T> getSerializationDelegate() {
@@ -1524,12 +1252,7 @@
@Override
public String toString() {
- return "{serializeNulls:"
- + serializeNulls
- + ",factories:"
- + factories
- + ",instanceCreators:"
- + constructorConstructor
- + "}";
- }
-}
+ { … 9 line(s) … ⟦tj:cc5d0e3daff3e1e0d5440186875b2827⟧ }
+[omitted blocks are individually retrievable: call tinyjuice_retrieve with the token inside an omission marker to expand just that block]
+
+[PARTIAL view — full original (68459 bytes): call tinyjuice_retrieve with token "85926a85e76809458c47cfd998fbcd1c"]
\ No newline at end of file