Hi Himasha, This looks like a similar issue like https://github.com/wso2/product-apim/issues/1607.
On Wed, Feb 21, 2018 at 8:11 PM, Himasha Guruge <himas...@wso2.com> wrote: > Hi, > > I'm trying out [1] with Api Manager 2.1.0. I have downloaded the java SDK > of PizzaShackAPI and tried to run APIClient main method. At first with the > exact same code, I was getting below error. > > > com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: > Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 > Normally we don't need to modify any generated code in the SDK. From the above error what it means is the SDK *expects* a payload starting with "{" (json object) but it received a payload starting with "[" (json array). What SDK decides as *expects* is what we define in the swagger: Because the SDK is actually generated using the swagger of the API (Chamin's article mentions the info in detail). If we look at the swagger definition of the /menu. /menu: get: x-auth-type: Application & Application User x-throttling-tier: Unlimited description: Return a list of available menu items parameters: [] responses: '200': headers: {} * schema:* * title: Menu* * properties:* * list:* * items:* * $ref: '#/definitions/MenuItem'* * type: array* * type: object* It specifies the response as { "list" : [ {*menu_item1} , { menu_item2 } .. *] } etc. This is a JSON object (starting with "{"). But seems like what you are getting as the actual response from /menu GET call is something like this: [ {*menu_item1} , { menu_item2 } .. *] (without the "list" part). This is a JSON array (starting with "["). This violates what we specified in the swagger. Can you fix the swagger as below from Publisher -> Edit -> Edit Source -> Save & Publish API and try generating the SDK from Store and invoking once again. /menu: get: x-auth-type: Application & Application User x-throttling-tier: Unlimited description: Return a list of available menu items parameters: [] responses: '200': description: OK. List of APIs is returned. headers: {} * schema:* * type: array* * items:* * $ref: '#/definitions/MenuItem'* If this works, lets create an issue to track this to fix in a future release. Thanks! > To sort it out I updated defaultAPI.java code of the SDK, to return a > List<Menu> instead, and it got sorted. (See changes below) > > public List<Menu> menuGet() throws ApiException { > ApiResponse<List<Menu>> resp = menuGetWithHttpInfo(); > return resp.getData(); > } > > > public ApiResponse<List<Menu>> menuGetWithHttpInfo() throws > ApiException { > com.squareup.okhttp.Call call = menuGetCall(null, null); > Type localVarReturnType = new TypeToken<List<Menu>>(){}.getType(); > return apiClient.execute(call, localVarReturnType); > } > > > However, now I'm getting a response but the menu list is empty. Any idea > what could be the issue? > > > [1]https://docs.wso2.com/display/AM210/Write+a+Client+ > Application+Using+the+SDK#1a97b57b1791422f99d81743523b612e > > Thanks, > Himasha Guruge > Senior Software Engineer > WS*O2* *Inc.* > Mobile: +94 777459299 <+94%2077%20745%209299> > himas...@wso2.com > > _______________________________________________ > Dev mailing list > Dev@wso2.org > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- Malintha Amarasinghe *WSO2, Inc. - lean | enterprise | middleware* http://wso2.com/ Mobile : +94 712383306
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev