public static String writePdxInstanceAsJson(JsonGenerator generator, PdxInstance pdxInstance)
      throws IOException {
    generator.writeStartObject();

    List<String> pdxFields = pdxInstance.getFieldNames();

    for (String pdxField : pdxFields) {
      Object value = pdxInstance.getField(pdxField);
      generator.writeFieldName(pdxField);
      writeValueAsJson(generator, value, pdxField);
    }
    generator.writeEndObject();
    return null;
  }
The JsonWriter class is an utility to write various java types as a JSON string.
<p>

@since GemFire 8.0
geode-web-api/src/main/java/org/apache/geode/rest/internal/web/util/JsonWriter.java