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

InfluxQLQueryApiImpl cannot cast JsonNull #808

Open
leonardo-belotti-aiknow opened this issue Jan 15, 2025 · 1 comment
Open

InfluxQLQueryApiImpl cannot cast JsonNull #808

leonardo-belotti-aiknow opened this issue Jan 15, 2025 · 1 comment

Comments

@leonardo-belotti-aiknow

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?

@NguyenHoangSon96
Copy link

HI @leonardo-belotti-aiknow
Can you capture the exception? I need more info
Any chance that the null is the "je" 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants