All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.nmorel.gwtjackson.client.deser.BooleanJsonDeserializer Maven / Gradle / Ivy

Go to download

gwt-jackson is a GWT JSON serializer/deserializer mechanism based on Jackson annotations

There is a newer version: 0.15.4
Show newest version
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