in streams-components/streams-converters/src/main/java/org/apache/streams/converter/HoconConverterUtil.java [80:137]
public Object convert(Object object, Class outClass, Config hocon, String inPath, String outPath) {
String json;
Object outDoc = null;
if ( object instanceof String ) {
json = (String) object;
} else {
try {
json = mapper.writeValueAsString(object);
} catch (JsonProcessingException ex) {
LOGGER.warn("Failed to process input:", object);
return outDoc;
}
}
Config base;
if( inPath == null) {
base = ConfigFactory.parseString(json);
} else {
ObjectNode node;
try {
node = mapper.readValue(json, ObjectNode.class);
ObjectNode root = mapper.createObjectNode();
root.set(inPath, node);
json = mapper.writeValueAsString(root);
base = ConfigFactory.parseString(json);
} catch (Exception ex) {
LOGGER.warn("Failed to process input:", object);
return outDoc;
}
}
Config converted = hocon.withFallback(base);
String outJson = null;
try {
if( outPath == null ) {
outJson = converted.resolve().root().render(ConfigRenderOptions.concise());
} else {
Config resolved = converted.resolve();
ConfigObject outObject = resolved.withOnlyPath(outPath).root();
ConfigValue outValue = outObject.get(outPath);
outJson = outValue.render(ConfigRenderOptions.concise());
}
} catch (Exception ex) {
LOGGER.warn("Failed to convert:", json);
LOGGER.warn(ex.getMessage());
}
if ( outClass == String.class )
return outJson;
else {
try {
outDoc = mapper.readValue( outJson, outClass );
} catch (IOException ex) {
LOGGER.warn("Failed to convert:", object);
}
}
return outDoc;
}