com.github.nmorel.gwtjackson.client.deser.BooleanJsonDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gwt-jackson Show documentation
Show all versions of gwt-jackson Show documentation
gwt-jackson is a GWT JSON serializer/deserializer mechanism based on Jackson annotations
package com.github.nmorel.gwtjackson.client.deser;
import java.io.IOException;
import com.github.nmorel.gwtjackson.client.JsonDeserializationContext;
import com.github.nmorel.gwtjackson.client.JsonDeserializer;
import com.github.nmorel.gwtjackson.client.stream.JsonReader;
import com.github.nmorel.gwtjackson.client.stream.JsonToken;
/**
* Default {@link JsonDeserializer} implementation for {@link Boolean}.
*
* @author Nicolas Morel
*/
public class BooleanJsonDeserializer extends JsonDeserializer {
private static final BooleanJsonDeserializer INSTANCE = new BooleanJsonDeserializer();
/**
* @return an instance of {@link BooleanJsonDeserializer}
*/
public static BooleanJsonDeserializer getInstance() {
return INSTANCE;
}
private BooleanJsonDeserializer() { }
@Override
public Boolean doDeserialize( JsonReader reader, JsonDeserializationContext ctx ) throws IOException {
JsonToken token = reader.peek();
if ( JsonToken.BOOLEAN.equals( token ) ) {
return reader.nextBoolean();
} else if ( JsonToken.STRING.equals( token ) ) {
return Boolean.valueOf( reader.nextString() );
} else if ( JsonToken.NUMBER.equals( token ) ) {
return reader.nextInt() == 1;
} else {
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy