Skip to content
This repository has been archived by the owner on Apr 1, 2019. It is now read-only.

Added option to retrieve boolean response from JSON content #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

padcom
Copy link

@padcom padcom commented Jul 2, 2015

Hi,

sometimes the content returned is a constant true/false. Since there is no way to set the content type for TextResource I've created the "toBoolean" method on JSONResource that simply casts the unmarshaled object to boolean.

I need this since the service I am integrating with is very strict in the content it accepts and can produce (application/json and nothing else) and returns a true/false value.

Best regards,
Matthias.

@padcom
Copy link
Author

padcom commented Jul 2, 2015

I've had problems building the solution because of some GPG plugin problem but I've tested the pull request otherwise directly from Eclipse and it worked OK.

/* Parse and return a boolean value
/*
public boolean bool() throws IOException, JSONException {
return (boolean)unmarshal();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think unmarshal() should only be called if it hasn't been unmarshalled already, and the value cached in json be cast and returned

if (json == null) unmarshal();
return (boolean)json;

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

Successfully merging this pull request may close these issues.

2 participants