Source:
private void exampleMap(MarkupDocBuilder markupDocBuilder, Map<String, Object> exampleMap, String operationSectionTitle, String sectionTitle) { if (exampleMap.size() > 0) { buildSectionTitle(markupDocBuilder, operationSectionTitle); for (Map.Entry<String, Object> entry : exampleMap.entrySet()) { buildExampleTitle(markupDocBuilder, sectionTitle + " " + entry.getKey()); if (NumberUtils.isNumber(entry.getKey())) { try { JsonFactory factory = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(factory); JsonNode rootNode = mapper.readTree(Json.pretty(entry.getValue())); Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields(); if (!fieldsIterator.hasNext()) { String example = Json.pretty(entry.getValue()) .replaceAll("^\"+", "") .replaceAll("\"+$", ""); example = Json.pretty(example); markupDocBuilder.listingBlock(example, "json"); } while (fieldsIterator.hasNext()) { Map.Entry<String, JsonNode> field = fieldsIterator.next(); if (field.getKey().equals("application/json")) { String example = Json.pretty(field.getValue()); example = StringEscapeUtils.unescapeJson(example) .replaceAll("^\"+", "") .replaceAll("\"+$", ""); markupDocBuilder.listingBlock(example, "json"); } else if (field.getKey().equals("application/xml")) { String example = field.getValue().toString() .replaceAll("^\"+", "") .replaceAll("\"+$", ""); example = StringEscapeUtils.unescapeJava(example); markupDocBuilder.listingBlock(example, "xml"); } else { String example = Json.pretty(entry.getValue()); markupDocBuilder.listingBlock(example, "json"); break; } } } catch (Exception ex) { } } else if (entry.getKey().equals("path")) { markupDocBuilder.listingBlock(entry.getValue().toString()); } else { markupDocBuilder.listingBlock(Json.pretty(entry.getValue()), "json"); } } } }

Target:
private void exampleMap(MarkupDocBuilder markupDocBuilder, Map<String, Object> exampleMap, String operationSectionTitle, String sectionTitle) { if (exampleMap.size() > 0) { buildSectionTitle(markupDocBuilder, operationSectionTitle); for (Map.Entry<String, Object> entry : exampleMap.entrySet()) { buildExampleTitle(markupDocBuilder, sectionTitle + " " + entry.getKey()); if (NumberUtils.isNumber(entry.getKey())) { JsonNode rootNode = parseExample(entry.getValue()); Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields(); if (!fieldsIterator.hasNext()) { String example = stripExampleQuotes(Json.pretty(entry.getValue())); example = Json.pretty(example); markupDocBuilder.listingBlock(example, "json"); } while (fieldsIterator.hasNext()) { Map.Entry<String, JsonNode> field = fieldsIterator.next(); if (field.getKey().equals("application/json")) { String example = Json.pretty(field.getValue()); example = stripExampleQuotes(StringEscapeUtils.unescapeJson(example)); markupDocBuilder.listingBlock(example, "json"); } else if (field.getKey().equals("application/xml")) { String example = stripExampleQuotes(field.getValue().toString()); example = StringEscapeUtils.unescapeJava(example); markupDocBuilder.listingBlock(example, "xml"); } else { String example = Json.pretty(entry.getValue()); markupDocBuilder.listingBlock(example, "json"); break; } } } else if (entry.getKey().equals("path")) { markupDocBuilder.listingBlock(entry.getValue().toString()); } else { markupDocBuilder.listingBlock(Json.pretty(entry.getValue()), "json"); } } } }