# Intended way to get InfluxDB2 results into POJOs in Java?

**URL:** <https://community.influxdata.com/t/intended-way-to-get-influxdb2-results-into-pojos-in-java/22499>\
**Category:** Client SDKs\
**Tags:** influxdb, java\
**Created:** [November 12, 2021, 10:48am UTC](https://community.influxdata.com/t/intended-way-to-get-influxdb2-results-into-pojos-in-java/22499 "2021-11-12T10:48:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_Doe](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@Bob\_Doe](https://community.influxdata.com/u/Bob_Doe)\
**Post date:** [November 12, 2021, 10:48am UTC](https://community.influxdata.com/t/intended-way-to-get-influxdb2-results-into-pojos-in-java/22499/1 "2021-11-12T10:48:47Z")

</div>

I’m able to insert to InfluxDB2 (on-prem) just fine with the `influx-client-java`, however I’m unsure how to properly “deal with” query results, which I get as a `List<FluxTable>`. Is there any simple way to get such a result back into POJOs, or use some other `query` function?

I’m using `client.getQueryApi().query("my flux query", "myorganization")`.

---

<div class="post-metadata">

**Author:** ![bednar](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/bednar/32/3690_2.png) [@bednar](https://community.influxdata.com/u/bednar)\
**Post date:** [November 12, 2021, 11:14am UTC](https://community.influxdata.com/t/intended-way-to-get-influxdb2-results-into-pojos-in-java/22499/2 "2021-11-12T11:14:57Z")

</div>

Hi @Bob_Doe,

thanks for using our client.

Check it out this example - [influxdb-client-java/SynchronousQueryPojo.java at master · influxdata/influxdb-client-java · GitHub](https://github.com/influxdata/influxdb-client-java/blob/master/examples/src/main/java/example/SynchronousQueryPojo.java#L33)

Regards

---

<div class="post-metadata">

**Author:** ![Bob\_Doe](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@Bob\_Doe](https://community.influxdata.com/u/Bob_Doe)\
**Post date:** [November 16, 2021, 9:39pm UTC](https://community.influxdata.com/t/intended-way-to-get-influxdb2-results-into-pojos-in-java/22499/3 "2021-11-16T21:39:23Z")

</div>

Thanks for your reply. I was able to review it, but as I’m fairly new to Influx apparently I don’t quite get it.

Say I have the following: A object that has two fields, say “val\_a” and “val\_b”. How am I able to convert a Flux query result back into a POJO while getting the following into variables:

- The measurement name
  - Say I ask for “measurement is X or Y or Z”, then I’d like my POJO to know if it is X or Y or Z.

- The value for BOTH “val\_a” and “val\_b” in a single POJO
  - Here I seem to get one but not the other. Is this because the POJO converter only concerns itself with a single FluxRecord…? I might be getting something wrong here.

So say that I insert:

```auto
my_measurement_1
  val_a = 1.23456
  val_b = 555

```

I’d like to query it out asking for for multiple measurements

- e.g. a filter for `r["_measurement"] == "my_measurement_1" or r["_measurement"] == "my_measurement_2" ...` an
- And a filter for `r["_field"] == "val_a" or r["_field"] == "val_b"`

And then be able to bring this back into X separate POJOs which all look (ideally, or as close as possible) like this (pseudocode):

```auto
[
Result {
  String name = "my_measurement_1";
  Double valA = 1.23456;
  Integer valB = 555;
}, 
Result {
  String name = "my_measurement_2";
  Double valA = 2.46802;
  Integer valB = 999;
},
...
]

```

**Feel free to modify if I’m modeling or querying poorly, or if I’m missing something else entirely.**

My current, rather unsuccessful attempt is something like:

```auto
@Measurement(name = "measurement") // ??? Dynamic? Why specific name?
public class Result {
  @Column(name = "val_a")
  Double valA;

  @Column(name = "val_b")
  Integer valB;

  @Column(timestamp = true)
  Instant time;
}

```

---

<div class="post-metadata">

**Author:** ![Bob\_Doe](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@Bob\_Doe](https://community.influxdata.com/u/Bob_Doe)\
**Post date:** [November 19, 2021, 9:53am UTC](https://community.influxdata.com/t/intended-way-to-get-influxdb2-results-into-pojos-in-java/22499/4 "2021-11-19T09:53:24Z")

</div>

After better understanding Influx and the way responses work I realize the fault was that I needed to `pivot` the column to get them in the same row.

Doing this pivot I could get them by name and also get what I call the “measurement name” with column named `_measurement`. E.g., after `pivot`:

```auto
public class Result {
  @Column(name = "_measurement")
  String measurement;

  @Column(name = "val_a")
  Double valA;

  @Column(name = "val_b")
  Integer valB;

  @Column(timestamp = true)
  Instant time;
}

```

Pivot could be like:

```auto
  |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")

```

---

<div class="post-metadata">

**Author:** ![bednar](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/bednar/32/3690_2.png) [@bednar](https://community.influxdata.com/u/bednar)\
**Post date:** [November 22, 2021, 7:49am UTC](https://community.influxdata.com/t/intended-way-to-get-influxdb2-results-into-pojos-in-java/22499/5 "2021-11-22T07:49:14Z")

</div>

@Bob_Doe sorry for the late.

You are right the `pivot` and the `@Column(name = "_measurement")` are valid solutions.
