Browse Source
Merge pull request #8002 from ShvaykaD/bugfix/entity-data-adapter-convert-value
[3.4.4] Fix data convertion for BigInteger values that stored in DB as String
pull/8010/head
Andrew Shvayka
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
10 additions and
3 deletions
-
dao/src/main/java/org/thingsboard/server/dao/sql/query/EntityDataAdapter.java
-
dao/src/test/java/org/thingsboard/server/dao/sql/query/EntityDataAdapterTest.java
|
|
@ -92,8 +92,9 @@ public class EntityDataAdapter { |
|
|
} |
|
|
} |
|
|
try { |
|
|
try { |
|
|
double dblVal = Double.parseDouble(strVal); |
|
|
double dblVal = Double.parseDouble(strVal); |
|
|
if (!Double.isInfinite(dblVal)) { |
|
|
String doubleAsString = Double.toString(dblVal); |
|
|
return Double.toString(dblVal); |
|
|
if (!Double.isInfinite(dblVal) && isSimpleDouble(doubleAsString)) { |
|
|
|
|
|
return doubleAsString; |
|
|
} |
|
|
} |
|
|
} catch (NumberFormatException ignored) { |
|
|
} catch (NumberFormatException ignored) { |
|
|
} |
|
|
} |
|
|
@ -104,4 +105,9 @@ public class EntityDataAdapter { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static boolean isSimpleDouble(String valueAsString) { |
|
|
|
|
|
return valueAsString.contains(".") && !valueAsString.contains("E") && !valueAsString.contains("e"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
@ -25,6 +25,7 @@ public class EntityDataAdapterTest { |
|
|
public void testConvertValue() { |
|
|
public void testConvertValue() { |
|
|
assertThat(EntityDataAdapter.convertValue("500")).isEqualTo("500"); |
|
|
assertThat(EntityDataAdapter.convertValue("500")).isEqualTo("500"); |
|
|
assertThat(EntityDataAdapter.convertValue("500D")).isEqualTo("500D"); //do not convert to Double !!!
|
|
|
assertThat(EntityDataAdapter.convertValue("500D")).isEqualTo("500D"); //do not convert to Double !!!
|
|
|
assertThat(EntityDataAdapter.convertValue("0101010521130565")).isEqualTo("0101010521130565"); |
|
|
assertThat(EntityDataAdapter.convertValue("0101010521130565")).isEqualTo("0101010521130565"); //do not convert to Double !!!
|
|
|
|
|
|
assertThat(EntityDataAdapter.convertValue("89010303310033979663")).isEqualTo("89010303310033979663"); //do not convert to Double !!!
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|