Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase jackson.version to 2.10.0.pr1 #1307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.3</version>
<version>3.5.0</version>
<executions>
<!-- Generate bundle manifest -->
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;


/**
* Openstack API V2 has a few Services which return a 'True' as a boolean value. Jackson typically will not realize that this is equivalent to 'true' and will throw an
* error. This Deserializer is a workaround to both problems
* Openstack API V2 has a few Services which return a 'True' as a boolean value.
* Jackson typically will not realize that this is equivalent to 'true' and will
* throw an error. This Deserializer is a workaround to both problems
*
* @author Jeremy Unruh
*/
Expand All @@ -23,64 +23,66 @@ public class OSBadBooleanDeserializer extends JsonDeserializer<Boolean> {
*/
@Override
public Boolean deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_TRUE) {
return Boolean.TRUE;
}
if (t == JsonToken.VALUE_FALSE) {
return Boolean.FALSE;
}
// [JACKSON-78]: should accept ints too, (0 == false, otherwise true)
if (t == JsonToken.VALUE_NUMBER_INT) {
// 11-Jan-2012, tatus: May be outside of int...
if (jp.getNumberType() == NumberType.INT) {
return (jp.getIntValue() == 0) ? Boolean.FALSE : Boolean.TRUE;
}
return Boolean.valueOf(_parseBooleanFromNumber(jp, ctxt));
}
if (t == JsonToken.VALUE_NULL) {
return getNullValue();
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
if ("true".equalsIgnoreCase(text)) {
return Boolean.TRUE;
}
if ("false".equalsIgnoreCase(text)) {
return Boolean.FALSE;
}
if (text.length() == 0) {
return getEmptyValue();
}
throw ctxt.weirdStringException(text, Boolean.class, "only \"true\" or \"false\" recognized");
}
// Otherwise, no can do:
throw ctxt.mappingException(Boolean.class, t);
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_TRUE) {
return Boolean.TRUE;
}
if (t == JsonToken.VALUE_FALSE) {
return Boolean.FALSE;
}
// [JACKSON-78]: should accept ints too, (0 == false, otherwise true)
if (t == JsonToken.VALUE_NUMBER_INT) {
// 11-Jan-2012, tatus: May be outside of int...
if (jp.getNumberType() == NumberType.INT) {
return (jp.getIntValue() == 0) ? Boolean.FALSE : Boolean.TRUE;
}
return Boolean.valueOf(_parseBooleanFromNumber(jp, ctxt));
}
if (t == JsonToken.VALUE_NULL) {
return getNullValue();
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
if ("true".equalsIgnoreCase(text)) {
return Boolean.TRUE;
}
if ("false".equalsIgnoreCase(text)) {
return Boolean.FALSE;
}
if (text.length() == 0) {
return getNullValue();
}
throw ctxt.weirdStringException(text, Boolean.class, "only \"true\" or \"false\" recognized");
}
// Otherwise, no can do:
throw ctxt.mappingException(Boolean.class, t);
}

/**
* _parse boolean from number.
*
* @param jp the jp
* @param ctxt the ctxt
* @param jp
* the jp
* @param ctxt
* the ctxt
* @return true, if successful
* @throws IOException Signals that an I/O exception has occurred.
* @throws JsonProcessingException the json processing exception
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws JsonProcessingException
* the json processing exception
*/
protected final boolean _parseBooleanFromNumber(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (jp.getNumberType() == NumberType.LONG) {
return (jp.getLongValue() == 0L) ? Boolean.FALSE : Boolean.TRUE;
}
// no really good logic; let's actually resort to textual comparison
String str = jp.getText();
if ("0.0".equals(str) || "0".equals(str)) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}

throws IOException, JsonProcessingException {
if (jp.getNumberType() == NumberType.LONG) {
return (jp.getLongValue() == 0L) ? Boolean.FALSE : Boolean.TRUE;
}
// no really good logic; let's actually resort to textual comparison
String str = jp.getText();
if ("0.0".equals(str) || "0".equals(str)) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<release.version>2.0.0</release.version>
<aries.spifly.version>1.0.0</aries.spifly.version>
<slf4j.version>1.7.21</slf4j.version>
<jackson.version>2.7.3</jackson.version>
<jackson.version>2.10.0.pr1</jackson.version>
<maven.jar.plugin.version>2.6</maven.jar.plugin.version>
<additionalparam>-Xdoclint:none</additionalparam>
</properties>
Expand Down