@@ -280,19 +280,15 @@ private void parse(
280280 } else if (value .isBoolean ()) {
281281 json .append (value .getAsBoolean ());
282282 } else if (value .isString ()) {
283- json .append ("\" " );
284- json .append (value .getAsString ().replace ("\" " , "\\ \" " ));
285- json .append ("\" " );
283+ appendJsonString (json , value .getAsString ());
286284 } else if (value .isDouble ()) {
287285 json .append (value .getAsDouble ());
288286 } else if (value .isInt ()) {
289287 json .append (value .getAsLong ());
290288 } else if (value .isNumber ()) {
291289 json .append (value .getAsNumber ());
292290 } 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 ()));
296292 } else if (value .isNull ()) {
297293 json .append (NULL );
298294 } else {
@@ -302,10 +298,7 @@ private void parse(
302298 }
303299
304300 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 );
309302 }
310303
311304 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
458451 }
459452 }
460453
454+ private static StringBuilder appendJsonString (final StringBuilder json , final String text ) {
455+ return json
456+ .append ("\" " )
457+ .append (text .replace ("\" " , "\\ \" " ))
458+ .append ("\" " );
459+ }
460+
461461 public static String toJSONString (final String text ) {
462462 final StringWriter writer = new StringWriter ();
463463 try {
0 commit comments