pratapaditya04 commented on code in PR #4057:
URL: https://github.com/apache/gobblin/pull/4057#discussion_r1764399946


##########
gobblin-api/src/main/java/org/apache/gobblin/util/io/GsonInterfaceAdapter.java:
##########
@@ -189,7 +192,38 @@ private <S> S readValue(JsonObject jsonObject, 
TypeToken<S> defaultTypeToken) th
   }
 
   public static <T> Gson getGson(Class<T> clazz) {
-    Gson gson = new GsonBuilder().registerTypeAdapterFactory(new 
GsonInterfaceAdapter(clazz)).create();
+    Gson gson = new GsonBuilder()
+        
.setObjectToNumberStrategy(CustomToNumberPolicy.INTEGER_OR_LONG_OR_DOUBLE)
+        .registerTypeAdapterFactory(new GsonInterfaceAdapter(clazz))
+        .create();
     return gson;
   }
+
+  public enum CustomToNumberPolicy implements ToNumberStrategy {
+    INTEGER_OR_LONG_OR_DOUBLE {
+      @Override
+      public Number readNumber(JsonReader in) throws IOException {
+        String value = in.nextString();
+        try {
+          return Integer.parseInt(value);
+        } catch (NumberFormatException var3) {
+          try {
+            return Long.parseLong(value);
+          } catch (NumberFormatException var2) {
+            try {
+              Double d = Double.valueOf(value);
+              if ((d.isInfinite() || d.isNaN()) && !in.isLenient()) {
+                throw new MalformedJsonException("JSON forbids NaN and 
infinities: " + d + "; at path " + in.getPath());

Review Comment:
   nit: prefer using String.format to improve readability and performance, as 
String concatenation using + can create multiple intermediate String objects, 
which impacts performance/
   For ex sample replacement : 
   `throw new JsonParseException(String.format("Cannot parse %s; at path %s", 
value, in.getPath()), var1);`
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to