You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gobblin.apache.org by ku...@apache.org on 2020/05/22 04:40:03 UTC

[incubator-gobblin] branch master updated: [GOBBLIN-1157] get a json representation of object if config type is different

This is an automated email from the ASF dual-hosted git repository.

kuyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-gobblin.git


The following commit(s) were added to refs/heads/master by this push:
     new 9aed23f  [GOBBLIN-1157] get a json representation of object if config type is different
9aed23f is described below

commit 9aed23f7ac17cb461b35837ffb901d145cfeb11b
Author: Arjun <ab...@linkedin.com>
AuthorDate: Thu May 21 21:39:52 2020 -0700

    [GOBBLIN-1157] get a json representation of object if config type is different
    
    Closes #2996 from arjun4084346/configList
---
 .../src/main/java/org/apache/gobblin/util/ConfigUtils.java    | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/gobblin-utility/src/main/java/org/apache/gobblin/util/ConfigUtils.java b/gobblin-utility/src/main/java/org/apache/gobblin/util/ConfigUtils.java
index 33b9e09..0af6614 100644
--- a/gobblin-utility/src/main/java/org/apache/gobblin/util/ConfigUtils.java
+++ b/gobblin-utility/src/main/java/org/apache/gobblin/util/ConfigUtils.java
@@ -341,14 +341,21 @@ public class ConfigUtils {
 
   /**
    * Return string value at <code>path</code> if <code>config</code> has path. If not return <code>def</code>
-   *
+   * If the config value is not of String type, it will try to get it as a generic Object type
+   * using {@see com.typesafe.config.Config#getAnyRef()} and then try to return its json representation as a string
    * @param config in which the path may be present
    * @param path key to look for in the config object
    * @return string value at <code>path</code> if <code>config</code> has path. If not return <code>def</code>
    */
   public static String getString(Config config, String path, String def) {
     if (config.hasPath(path)) {
-      return config.getString(path);
+      String value;
+      try {
+        value = config.getString(path);
+      } catch (ConfigException.WrongType wrongType) {
+        value = new Gson().toJson(config.getAnyRef(path));
+      }
+      return value;
     }
     return def;
   }