Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mapping measurement with primitive float #294

Merged
merged 2 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
### Bug Fixes
1. [#283](https://github.com/influxdata/influxdb-client-java/pull/283): Serialization `null` tag's value into LineProtocol
1. [#285](https://github.com/influxdata/influxdb-client-java/pull/285): Default dialect for Query APIs
1. [#294](https://github.com/influxdata/influxdb-client-java/pull/294): Mapping measurement with primitive `float`

## 4.0.0 [2021-11-26]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ private boolean isNumber(@Nonnull final Class<?> fieldType) {
return Number.class.isAssignableFrom(fieldType)
|| double.class.isAssignableFrom(fieldType)
|| long.class.isAssignableFrom(fieldType)
|| float.class.isAssignableFrom(fieldType)
|| int.class.isAssignableFrom(fieldType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class MeasurementMapperTest {
private MeasurementMapper mapper;

@BeforeEach
void setUp()
{
void setUp() {
mapper = new MeasurementMapper();
}

Expand Down Expand Up @@ -133,6 +132,24 @@ void pojoMeasurement() {
Assertions.assertThat(lineProtocol).isEqualTo("mem,tag=a value=5i");
}

@Test
void primitives() {
PojoPrimitives pojo = new PojoPrimitives();
pojo.float1 = 10.5F;
pojo.float2 = pojo.float1;
pojo.integer1 = 50;
pojo.integer2 = pojo.integer1;
pojo.bool1 = true;
pojo.bool2 = pojo.bool1;
pojo.double1 = 123.12;
pojo.double2 = pojo.double1;
pojo.long1 = 123456789L;
pojo.long2 = pojo.long1;

String lineProtocol = mapper.toPoint(pojo, WritePrecision.S).toLineProtocol();
Assertions.assertThat(lineProtocol).isEqualTo("primitives bool1=true,bool2=true,double1=123.12,double2=123.12,float1=10.5,float2=10.5,integer1=50i,integer2=50i,long1=123456789i,long2=123456789i");
}

@Measurement(name = "pojo")
private static class Pojo {

Expand Down Expand Up @@ -177,4 +194,32 @@ public static class PojoMeasurement {
@Column(name = "value")
private Integer value;
}

@Measurement(name = "primitives")
public static class PojoPrimitives {
@Column
private Float float1;
@Column
private float float2;

@Column
private Integer integer1;
@Column
private int integer2;

@Column
private Boolean bool1;
@Column
private boolean bool2;

@Column
private Double double1;
@Column
private double double2;

@Column
private Long long1;
@Column
private long long2;
}
}