watson-developer-cloud / java-sdk

:1st_place_medal: Java SDK to use the IBM Watson services.
http://watson-developer-cloud.github.io/java-sdk/
Apache License 2.0
593 stars 532 forks source link

Expected BEGIN_OBJECT but was BEGIN_ARRAY exception encountered passing Discovery data to Watson sdk #552

Closed JamieGilbertIBM closed 7 years ago

JamieGilbertIBM commented 7 years ago

We have a customer who is trying to run Discovery code using the Watson java sdk "java-sdk-3.5.3-jar-with-dependencies.jar", the following:

API call: 
GetConfigurationRequest getRequest = new GetConfigurationRequest.Builder(environmentId, configurationId).build(); 
GetConfigurationResponse resp = discovery.getConfiguration(getRequest).execute();

with:

environmentId: 88f61a29-12be-4e45-99d0-6f3d653658f4 
configurationId: c1451f13-951c-40d3-ae6e-482de9a77b3d

is returning:

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY 
at
line 39 column 20 path $.conversions.word.heading.styles

Based on preliminary investigation, the "line 39 column 20" in the sdk referred to in the stack trace is referring to the JSON response stream. And what the Expected BEGIN_OBJECT but was BEGIN_ARRAY error usually signifies is that the code is trying to pass an array return type into an object as opposed to creating an array to store the data.

The strange thing is that the customer's two lines of code are working fine for the default configuration of the read-only environment (in this case the configuration, or some part of it, is a single JSON object), while they are wrong for the configuration of the environment that was created by the Discovery Service online tool (in this case the configuration, or some part of it, looks like a JSON array).

So I can't tell if this is an issue with the sdk not correctly handling what Discovery considers valid output, or if the Discovery service needs to adjust how it outputs data in order to be compatible with the sdk?

maniax89 commented 7 years ago

Looks like a duplicate of https://github.com/watson-developer-cloud/java-sdk/issues/528