...
|
...
|
@@ -226,19 +226,29 @@ public class JsonConverter { |
226
|
226
|
}
|
227
|
227
|
|
228
|
228
|
private static KeyValueProto buildNumericKeyValueProto(JsonPrimitive value, String key) {
|
229
|
|
- if (value.getAsString().contains(".")) {
|
230
|
|
- return KeyValueProto.newBuilder()
|
231
|
|
- .setKey(key)
|
232
|
|
- .setType(KeyValueType.DOUBLE_V)
|
233
|
|
- .setDoubleV(value.getAsDouble())
|
234
|
|
- .build();
|
|
229
|
+ String valueAsString = value.getAsString();
|
|
230
|
+ KeyValueProto.Builder builder = KeyValueProto.newBuilder().setKey(key);
|
|
231
|
+ if (valueAsString.contains("e") || valueAsString.contains("E")) {
|
|
232
|
+ //TODO: correct value conversion. We should make sure that if the value can't fit into Long or Double, we should send String
|
|
233
|
+ var bd = new BigDecimal(valueAsString);
|
|
234
|
+ if (bd.stripTrailingZeros().scale() <= 0) {
|
|
235
|
+ try {
|
|
236
|
+ return builder.setType(KeyValueType.LONG_V).setLongV(bd.longValueExact()).build();
|
|
237
|
+ } catch (ArithmeticException e) {
|
|
238
|
+ return builder.setType(KeyValueType.DOUBLE_V).setDoubleV(bd.doubleValue()).build();
|
|
239
|
+ }
|
|
240
|
+ } else {
|
|
241
|
+ return builder.setType(KeyValueType.DOUBLE_V).setDoubleV(bd.doubleValue()).build();
|
|
242
|
+ }
|
|
243
|
+ } else if (valueAsString.contains(".")) {
|
|
244
|
+ return builder.setType(KeyValueType.DOUBLE_V).setDoubleV(value.getAsDouble()).build();
|
235
|
245
|
} else {
|
236
|
246
|
try {
|
237
|
247
|
long longValue = Long.parseLong(value.getAsString());
|
238
|
|
- return KeyValueProto.newBuilder().setKey(key).setType(KeyValueType.LONG_V)
|
239
|
|
- .setLongV(longValue).build();
|
|
248
|
+ return builder.setType(KeyValueType.LONG_V).setLongV(longValue).build();
|
240
|
249
|
} catch (NumberFormatException e) {
|
241
|
|
- throw new JsonSyntaxException("Big integer values are not supported!");
|
|
250
|
+ //TODO: correct value conversion. We should make sure that if the value can't fit into Long or Double, we should send String
|
|
251
|
+ return builder.setType(KeyValueType.DOUBLE_V).setDoubleV(new BigDecimal(valueAsString).doubleValue()).build();
|
242
|
252
|
}
|
243
|
253
|
}
|
244
|
254
|
}
|
...
|
...
|
@@ -252,6 +262,7 @@ public class JsonConverter { |
252
|
262
|
String valueAsString = value.getAsString();
|
253
|
263
|
String key = valueEntry.getKey();
|
254
|
264
|
if (valueAsString.contains("e") || valueAsString.contains("E")) {
|
|
265
|
+ //TODO: correct value conversion. We should make sure that if the value can't fit into Long or Double, we should send String
|
255
|
266
|
var bd = new BigDecimal(valueAsString);
|
256
|
267
|
if (bd.stripTrailingZeros().scale() <= 0) {
|
257
|
268
|
try {
|
...
|
...
|
@@ -269,7 +280,8 @@ public class JsonConverter { |
269
|
280
|
long longValue = Long.parseLong(value.getAsString());
|
270
|
281
|
result.add(new LongDataEntry(key, longValue));
|
271
|
282
|
} catch (NumberFormatException e) {
|
272
|
|
- throw new JsonSyntaxException("Big integer values are not supported!");
|
|
283
|
+ //TODO: correct value conversion. We should make sure that if the value can't fit into Long or Double, we should send String
|
|
284
|
+ result.add(new DoubleDataEntry(key, new BigDecimal(valueAsString).doubleValue()));
|
273
|
285
|
}
|
274
|
286
|
}
|
275
|
287
|
}
|
...
|
...
|
|