influxdb-client-java icon indicating copy to clipboard operation
influxdb-client-java copied to clipboard

InfluxQLQueryApiImpl cannot cast JsonNull

Open leonardo-belotti-aiknow opened this issue 10 months ago • 3 comments
trafficstars

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<Object> values = new ArrayList();
                            JsonArray jae = jval.getAsJsonArray();
                            int index = 0;

                            for(JsonElement je : jae) {
                                List<String> 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?

leonardo-belotti-aiknow avatar Jan 15 '25 08:01 leonardo-belotti-aiknow