influxdata / influxdata/influxdb-client-java

InfluxQLQueryApiImpl cannot cast JsonNull

Open
#808 3 comments 0 reactions 1 assignee View on GitHub

@NguyenHoangSon96 is already working on this.

Since Feb 3, 2025.

Dominant language
Java
Stars
477
Forks
129
PR merge metrics
No merged PRs in 30d

Description

Hi,
I'm trying to use `queryJSON` method of `InfluxQLQueryApi`.
If I have `null` values resulting from my query, the library fires an exception because of the cast forced to String.

As we can see from line 337 of the class:

```
JsonArray jvals = sobj.get("values").getAsJsonArray();
if (jvals != null) {
for(JsonElement jval : jvals) {
List values = new ArrayList();
JsonArray jae = jval.getAsJsonArray();
int index = 0;

for(JsonElement je : jae) {
List columnKeys = new ArrayList(serie.getColumns().keySet());
if (this.extractor != null) {
String stringVal = je.getAsString();
Object ov = this.extractor.extractValue((String)columnKeys.get(index), stringVal, id, serie.getName());
values.add(ov);
} else {
values.add(je.getAsString());
}

++index;
}

Objects.requireNonNull(serie);
serie.addRecord(new InfluxQLQueryResult.Series.Record(serie, values.toArray()));
}
}
```

When it gets the `null` value, the instruction `String stringVal = je.getAsString();` fires the exception.

Am I doing something wrong?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.