@@ -110,6 +110,7 @@ public final class Gson {
110
110
static final boolean DEFAULT_SERIALIZE_NULLS = false ;
111
111
static final boolean DEFAULT_COMPLEX_MAP_KEYS = false ;
112
112
static final boolean DEFAULT_SPECIALIZE_FLOAT_VALUES = false ;
113
+ static final boolean DEFAULT_USE_JDK_UNSAFE = true ;
113
114
114
115
private static final TypeToken <?> NULL_KEY_SURROGATE = TypeToken .get (Object .class );
115
116
private static final String JSON_NON_EXECUTABLE_PREFIX = ")]}'\n " ;
@@ -141,6 +142,7 @@ public final class Gson {
141
142
final boolean prettyPrinting ;
142
143
final boolean lenient ;
143
144
final boolean serializeSpecialFloatingPointValues ;
145
+ final boolean useJdkUnsafe ;
144
146
final String datePattern ;
145
147
final int dateStyle ;
146
148
final int timeStyle ;
@@ -189,6 +191,7 @@ public Gson() {
189
191
Collections .<Type , InstanceCreator <?>>emptyMap (), DEFAULT_SERIALIZE_NULLS ,
190
192
DEFAULT_COMPLEX_MAP_KEYS , DEFAULT_JSON_NON_EXECUTABLE , DEFAULT_ESCAPE_HTML ,
191
193
DEFAULT_PRETTY_PRINT , DEFAULT_LENIENT , DEFAULT_SPECIALIZE_FLOAT_VALUES ,
194
+ DEFAULT_USE_JDK_UNSAFE ,
192
195
LongSerializationPolicy .DEFAULT , null , DateFormat .DEFAULT , DateFormat .DEFAULT ,
193
196
Collections .<TypeAdapterFactory >emptyList (), Collections .<TypeAdapterFactory >emptyList (),
194
197
Collections .<TypeAdapterFactory >emptyList (), ToNumberPolicy .DOUBLE , ToNumberPolicy .LAZILY_PARSED_NUMBER );
@@ -198,22 +201,24 @@ public Gson() {
198
201
Map <Type , InstanceCreator <?>> instanceCreators , boolean serializeNulls ,
199
202
boolean complexMapKeySerialization , boolean generateNonExecutableGson , boolean htmlSafe ,
200
203
boolean prettyPrinting , boolean lenient , boolean serializeSpecialFloatingPointValues ,
204
+ boolean useJdkUnsafe ,
201
205
LongSerializationPolicy longSerializationPolicy , String datePattern , int dateStyle ,
202
206
int timeStyle , List <TypeAdapterFactory > builderFactories ,
203
207
List <TypeAdapterFactory > builderHierarchyFactories ,
204
208
List <TypeAdapterFactory > factoriesToBeAdded ,
205
- ToNumberStrategy objectToNumberStrategy , ToNumberStrategy numberToNumberStrategy ) {
209
+ ToNumberStrategy objectToNumberStrategy , ToNumberStrategy numberToNumberStrategy ) {
206
210
this .excluder = excluder ;
207
211
this .fieldNamingStrategy = fieldNamingStrategy ;
208
212
this .instanceCreators = instanceCreators ;
209
- this .constructorConstructor = new ConstructorConstructor (instanceCreators );
213
+ this .constructorConstructor = new ConstructorConstructor (instanceCreators , useJdkUnsafe );
210
214
this .serializeNulls = serializeNulls ;
211
215
this .complexMapKeySerialization = complexMapKeySerialization ;
212
216
this .generateNonExecutableJson = generateNonExecutableGson ;
213
217
this .htmlSafe = htmlSafe ;
214
218
this .prettyPrinting = prettyPrinting ;
215
219
this .lenient = lenient ;
216
220
this .serializeSpecialFloatingPointValues = serializeSpecialFloatingPointValues ;
221
+ this .useJdkUnsafe = useJdkUnsafe ;
217
222
this .longSerializationPolicy = longSerializationPolicy ;
218
223
this .datePattern = datePattern ;
219
224
this .dateStyle = dateStyle ;
0 commit comments