public static void writeStructAsJson(JsonGenerator generator, StructImpl element)
      throws IOException {
    generator.writeStartObject();

    String[] fieldNames = element.getFieldNames();
    for (final String fieldName : fieldNames) {
      // Iterate over Map and write key-value
      generator.writeFieldName(fieldName); // write Key in a Map
      Object value = element.get(fieldName);
      writeValueAsJson(generator, value, null); // write value in a Map
    }
    generator.writeEndObject();
  }
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