|
1 | 1 | package org.influxdb.dto;
|
2 | 2 |
|
3 | 3 | import org.influxdb.BuilderException;
|
| 4 | +import org.influxdb.InfluxDBMapperException; |
4 | 5 | import org.influxdb.annotation.Column;
|
5 | 6 | import org.influxdb.annotation.Exclude;
|
6 | 7 | import org.influxdb.annotation.Measurement;
|
@@ -322,20 +323,25 @@ private void addFieldByAttribute(final Object pojo, final Field field, final boo
|
322 | 323 | Object fieldValue = field.get(pojo);
|
323 | 324 |
|
324 | 325 | TimeColumn tc = field.getAnnotation(TimeColumn.class);
|
325 |
| - if (tc != null && Instant.class.isAssignableFrom(field.getType())) { |
326 |
| - Optional.ofNullable((Instant) fieldValue).ifPresent(instant -> { |
327 |
| - TimeUnit timeUnit = tc.timeUnit(); |
328 |
| - if (timeUnit == TimeUnit.NANOSECONDS || timeUnit == TimeUnit.MICROSECONDS) { |
329 |
| - this.time = BigInteger.valueOf(instant.getEpochSecond()) |
330 |
| - .multiply(NANOSECONDS_PER_SECOND) |
331 |
| - .add(BigInteger.valueOf(instant.getNano())) |
332 |
| - .divide(BigInteger.valueOf(TimeUnit.NANOSECONDS.convert(1, timeUnit))); |
333 |
| - } else { |
334 |
| - this.time = timeUnit.convert(instant.toEpochMilli(), TimeUnit.MILLISECONDS); |
335 |
| - } |
336 |
| - this.precision = timeUnit; |
337 |
| - }); |
338 |
| - return; |
| 326 | + if (tc != null) { |
| 327 | + if (Instant.class.isAssignableFrom(field.getType())) { |
| 328 | + Optional.ofNullable((Instant) fieldValue).ifPresent(instant -> { |
| 329 | + TimeUnit timeUnit = tc.timeUnit(); |
| 330 | + if (timeUnit == TimeUnit.NANOSECONDS || timeUnit == TimeUnit.MICROSECONDS) { |
| 331 | + this.time = BigInteger.valueOf(instant.getEpochSecond()) |
| 332 | + .multiply(NANOSECONDS_PER_SECOND) |
| 333 | + .add(BigInteger.valueOf(instant.getNano())) |
| 334 | + .divide(BigInteger.valueOf(TimeUnit.NANOSECONDS.convert(1, timeUnit))); |
| 335 | + } else { |
| 336 | + this.time = timeUnit.convert(instant.toEpochMilli(), TimeUnit.MILLISECONDS); |
| 337 | + } |
| 338 | + this.precision = timeUnit; |
| 339 | + }); |
| 340 | + return; |
| 341 | + } |
| 342 | + |
| 343 | + throw new InfluxDBMapperException( |
| 344 | + "Unsupported type " + field.getType() + " for time: should be of Instant type"); |
339 | 345 | }
|
340 | 346 |
|
341 | 347 | if (tag) {
|
|
0 commit comments