SABnzbd API Issue Re: slots:""

Report & discuss bugs found in SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
r1pclaw
Newbie
Newbie
Posts: 6
Joined: September 22nd, 2010, 12:58 pm

SABnzbd API Issue Re: slots:""

Post by r1pclaw »

I've been playing with google's gson (version 1.5) library, and it works wonders for parsing the JSON output (SABnzbd version 0.5.4), however I have come across a bit of an issue with the way "slots" are reported.

When there are no slots in use (noofslots: 0)  slots are reported with:
"slots":""

Which implies to the library that it is a string not an array.
When there are slots in use it is reported as:
"slots":[{"status":"Queued","index":0,"eta":"unknown"......

If there are no values in the array, it should report

"slots":[]

As a result, the library throws
java.lang.ClassCastException: com.google.gson.JsonPrimitive cannot be cast to com.google.gson.JsonArray

I have been using a string replace before putting it through the GSON parser to get around the issue.
IE

string.replace("slots\":\"\"", "slots\":[]");

Maybe something to be fixed in the future,  I couldn't find this issue in the forums, sorry if it's a double post.
Last edited by r1pclaw on September 22nd, 2010, 1:09 pm, edited 1 time in total.
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: SABnzbd API Issue Re: slots:""

Post by shypike »

It looks incorrect indeed.
I'll see if I can fix it.

Isn't the problem more in your own code than in gson?
slots : "" is valid json.
It's only that you don't know in advance whether you get a string or a list.
Last edited by shypike on September 22nd, 2010, 1:24 pm, edited 1 time in total.
r1pclaw
Newbie
Newbie
Posts: 6
Joined: September 22nd, 2010, 12:58 pm

Re: SABnzbd API Issue Re: slots:""

Post by r1pclaw »

Awesome, that was fast :P
r1pclaw
Newbie
Newbie
Posts: 6
Joined: September 22nd, 2010, 12:58 pm

Re: SABnzbd API Issue Re: slots:""

Post by r1pclaw »

Oh, and that was for the 'queue' JSON response, I haven't investigated the history one yet.
r1pclaw
Newbie
Newbie
Posts: 6
Joined: September 22nd, 2010, 12:58 pm

Re: SABnzbd API Issue Re: slots:""

Post by r1pclaw »

I was looking at this:
https://docs.sonatype.com/display/NX/Em ... cification

So i'm guessing that google is using that kind of standard for parsing.

The code for parsing:

Gson gson = new Gson();
SabQueue que = null;
//This grabs the queue information, cfg is an object holding host,port,SSL,apikey
String data = HttpInterface.getData(buildRequest(cfg,SabQueries.QUEUE,null));
if(data != null)
{
//here is the actual parsing (i strip off the {"queue": and trailing '}'
que = gson.fromJson(data.substring(9,data.length()-1) , SabQueue.class);
}

And it delivers me an object that is fully populated.

Of course, SabQueue is an object that has all of the fields reported by the sabnzbd queue request, and all getter/setters so that gson can figure it out by field names
Last edited by r1pclaw on September 22nd, 2010, 1:36 pm, edited 1 time in total.
r1pclaw
Newbie
Newbie
Posts: 6
Joined: September 22nd, 2010, 12:58 pm

Re: SABnzbd API Issue Re: slots:""

Post by r1pclaw »

The "scripts" field is an array as well (on a Queue json request), but it reports an empty array as:
"scripts":[]
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: SABnzbd API Issue Re: slots:""

Post by shypike »

Yeah, I found the culprit.

Code: Select all

    if slotinfo:
        info['slots'] = slotinfo
    else:
        info['slots'] = ''
Will fix it in the next release.
r1pclaw
Newbie
Newbie
Posts: 6
Joined: September 22nd, 2010, 12:58 pm

Re: SABnzbd API Issue Re: slots:""

Post by r1pclaw »

Right on, not a difficult issue to get around, just had me stumped for a bit.

Thanks!
Post Reply