public static void toJSON(OutputWriter outputWriter, ElasticProfile elasticProfile) { outputWriter .addLinks(linksWriter -> linksWriter .addLink("self", Routes.ElasticProfileAPI.id(elasticProfile.getId())) .addAbsoluteLink("doc", Routes.ElasticProfileAPI.DOC) .addLink("find", Routes.ElasticProfileAPI.find())) .add("id", elasticProfile.getId()) .add("plugin_id", elasticProfile.getPluginId()) .addChildList("properties", listWriter -> elasticProfile.forEach(property -> listWriter.addChild(propertyWriter -> ConfigurationPropertyRepresenter.toJSON(propertyWriter, property)))); if (elasticProfile.hasErrors()) { Map<String, String> fieldMapping = Collections.singletonMap("pluginId", "plugin_id"); outputWriter.addChild("errors", errorWriter -> new ErrorGetter(fieldMapping).toJSON(errorWriter, elasticProfile)); } }