@@ -280,19 +280,15 @@ private void parse(
280
280
} else if (value .isBoolean ()) {
281
281
json .append (value .getAsBoolean ());
282
282
} else if (value .isString ()) {
283
- json .append ("\" " );
284
- json .append (value .getAsString ().replace ("\" " , "\\ \" " ));
285
- json .append ("\" " );
283
+ appendJsonString (json , value .getAsString ());
286
284
} else if (value .isDouble ()) {
287
285
json .append (value .getAsDouble ());
288
286
} else if (value .isInt ()) {
289
287
json .append (value .getAsLong ());
290
288
} else if (value .isNumber ()) {
291
289
json .append (value .getAsNumber ());
292
290
} else if (value .isDate ()) {
293
- json .append ("\" " );
294
- json .append (DateUtil .format (value .getAsDate ()).replace ("\" " , "\\ \" " ));
295
- json .append ("\" " );
291
+ appendJsonString (json , DateUtil .format (value .getAsDate ()));
296
292
} else if (value .isNull ()) {
297
293
json .append (NULL );
298
294
} else {
@@ -302,10 +298,7 @@ private void parse(
302
298
}
303
299
304
300
private static void appendField (final String attribute , final StringBuilder json ) {
305
- json .append ("\" " );
306
- json .append (attribute .replace ("\" " , "\\ \" " ));
307
- json .append ("\" " );
308
- json .append (FIELD );
301
+ appendJsonString (json , attribute ).append (FIELD );
309
302
}
310
303
311
304
private void parseObject (final VPackSlice value , final StringBuilder json , final boolean includeNullValues )
@@ -458,6 +451,13 @@ private void parseValue(final VPackBuilder builder, final String fieldName, fina
458
451
}
459
452
}
460
453
454
+ private static StringBuilder appendJsonString (final StringBuilder json , final String text ) {
455
+ return json
456
+ .append ("\" " )
457
+ .append (text .replace ("\" " , "\\ \" " ))
458
+ .append ("\" " );
459
+ }
460
+
461
461
public static String toJSONString (final String text ) {
462
462
final StringWriter writer = new StringWriter ();
463
463
try {
0 commit comments