softlayer-java icon indicating copy to clipboard operation
softlayer-java copied to clipboard

setResultLimit with limit 1 throws an Exception in Gson parser

Open auvn opened this issue 11 years ago • 3 comments

Way to reproduce: ApiClient client = new RestApiClient().withLoggingEnabled().withCredentials( "userid", "apikey" ); Account.Service service = Account.service( client ); service.setResultLimit( new ResultLimit( 1,1 ) ); service.getHardware();

In result the JavaClient makes the following request:

https://api.softlayer.com/rest/v3.1/SoftLayer_Account/Hardware.json?resultLimit=1,1

And SL API returns a single Json object instead of array of Json objects, but Gson is expecting list of Json objects and we are facing with the following exception:

Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

I think you need a fix on SL Rest API side :)

Thanks in advance.

auvn avatar Apr 16 '15 11:04 auvn

In this case, we cannot change the REST API response here even though it is obviously unintuitive to have something that says it returns an array return a single object. I will have to make a Gson custom deserializer to handle this.

cretz avatar Apr 16 '15 15:04 cretz

This has been fixed in master. I will leave this open until we release the next version to maven with this fix in it.

cretz avatar Apr 16 '15 19:04 cretz

Released 0.2.3 which should address this issue.

camporter avatar Nov 28 '16 21:11 camporter