khandelwal-prateek commented on code in PR #4057:
URL: https://github.com/apache/gobblin/pull/4057#discussion_r1763611920


##########
gobblin-api/src/test/java/org/apache/gobblin/util/io/GsonInterfaceAdapterTest.java:
##########
@@ -43,4 +44,21 @@ public void test() {
 
   }
 
+  @Test
+  public void testObjectToIntegerDeserialize() {
+    Gson gson = new GsonBuilder().create();
+    Integer test = 5;

Review Comment:
   please add test for other scenarios i.e. long, floating point numbers and 
invalid string



##########
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(INTEGERNUMBERPOLICY.INTEGER_OR_LONG_OR_DOUBLE)
+        .registerTypeAdapterFactory(new GsonInterfaceAdapter(clazz))
+        .create();
     return gson;
   }
+
+  public enum INTEGERNUMBERPOLICY implements ToNumberStrategy {

Review Comment:
   enums are named in camel case.. can rename enum to something like 
`CustomNumberStrategy / NumberHandlingPolicy`



##########
gobblin-api/src/test/java/org/apache/gobblin/util/io/GsonInterfaceAdapterTest.java:
##########
@@ -43,4 +44,21 @@ public void test() {
 
   }
 
+  @Test
+  public void testObjectToIntegerDeserialize() {
+    Gson gson = new GsonBuilder().create();
+    Integer test = 5;
+    String ser = gson.toJson(test);
+    Object deser = gson.fromJson(ser, Object.class);
+    Assert.assertNotEquals(test, deser);

Review Comment:
   we can also assert on the type of object returned(double) by default gson 
deserializer



-- 
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: dev-unsubscr...@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to