Skip to content

Commit

Permalink
fix integer / number type sensing
Browse files Browse the repository at this point in the history
  • Loading branch information
aeberhart committed Sep 27, 2024
1 parent 362217b commit a1c5a7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,18 @@ public static String type(String pk, List<Map<String, Object>> table) {
}
if (o instanceof Date)
types.add("date");
if (o instanceof Integer)
types.add("integer");

if (o instanceof Integer) {
if (!types.contains("number"))
types.add("integer");
} else if (o instanceof Number) {
if (types.contains("integer"))
types.remove("integer");
types.add("number");
}

if (o instanceof Boolean)
types.add("boolean");
if (o instanceof Number)
types.add("number");
if (o instanceof List)
types.add("array");
if (o instanceof Map)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public void testMixed() {
Assertions.assertEquals("string", Provider.type("x", asList(of("x", 1), of("x", "string"))));
}

@Test
public void testIntNumber() {
Assertions.assertEquals("integer", Provider.type("x", asList(of("x", 1))));
Assertions.assertEquals("integer", Provider.type("x", asList(of("x", 1), of("x", 1))));
}

@Test
public void testNumber() {
Assertions.assertEquals("number", Provider.type("x", asList(of("x", 1.2))));
Assertions.assertEquals("number", Provider.type("x", asList(of("x", 1), of("x", 1.2))));
}

@Test
public void testNull() {
Assertions.assertEquals("string", Provider.type("x", asList(of("x", null), of("x", null))));
Expand Down

0 comments on commit a1c5a7c

Please sign in to comment.