001/*
002 * Copyright (c) 2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Nuxeo
011 */
012package org.nuxeo.ecm.automation.client.jaxrs.spi.marshallers;
013
014import java.io.IOException;
015
016import org.codehaus.jackson.JsonGenerator;
017import org.codehaus.jackson.JsonParser;
018import org.nuxeo.ecm.automation.client.jaxrs.spi.JsonMarshaller;
019
020/**
021 * Marshaller for the default ObjectCodec for the java Boolean class instances.
022 *
023 * @author ogrisel
024 * @since 5.7
025 */
026public class BooleanMarshaller implements JsonMarshaller<Boolean> {
027
028    @Override
029    public String getType() {
030        return "boolean";
031    }
032
033    @Override
034    public Class<Boolean> getJavaType() {
035        return Boolean.class;
036    }
037
038    @Override
039    public Boolean read(JsonParser jp) throws IOException {
040        jp.nextToken();
041        jp.nextToken();
042        return jp.readValueAs(Boolean.class);
043    }
044
045    @Override
046    public void write(JsonGenerator jg, Object value) throws IOException {
047        // No need to escape
048        jg.writeBoolean((Boolean) value);
049    }
050
051}