Skip to content

Commit 602d7c8

Browse files
authored
Merge pull request #1 from johnprisco/numeric-strings
Prevent NumberFormatException when strings consist only of numbers
2 parents a36404c + 8f2d51e commit 602d7c8

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/main/java/com/github/terma/sqlonjson/SqlOnJson.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ private static LinkedHashMap<String, ColumnType> getColumns(JsonTable jsonTable)
9494
}
9595
}
9696

97-
cls.put(part.getKey(), columnType);
97+
ColumnType current = cls.get(part.getKey());
98+
if (current == null || current != ColumnType.STRING) cls.put(part.getKey(), columnType);
9899
}
99100
}
100101
return cls;

src/test/java/com/github/terma/sqlonjson/SqlOnJsonTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ public void representEmbeddedObjectAsString() throws Exception {
162162
}
163163
}
164164

165+
@Test
166+
public void representNumericStringAsString() throws Exception {
167+
try (Connection c = sqlOnJson.convertPlain("{t:[{a:\"super\"},{a:\"5\"}]}")) {
168+
ResultSet rs = c.prepareStatement("select * from t").executeQuery();
169+
rs.next();
170+
Assert.assertEquals("super", rs.getString("a"));
171+
rs.next();
172+
Assert.assertEquals("5", rs.getString("a"));
173+
Assert.assertFalse(rs.next());
174+
}
175+
}
176+
165177
@Test
166178
public void supportEmbeddedArrayToTable() throws Exception {
167179
try (Connection c = sqlOnJson.convertPlain("{orders:[{em:[{a:-7}]}]}")) {

0 commit comments

Comments
 (0)