org.eyeseetea.malariacare.layout.dashboard.deserializers.DashboardOrientationDeserializer.java Source code

Java tutorial

Introduction

Here is the source code for org.eyeseetea.malariacare.layout.dashboard.deserializers.DashboardOrientationDeserializer.java

Source

/*
 * Copyright (c) 2016.
 *
 * This file is part of QA App.
 *
 *  Health Network QIS App is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Health Network QIS App is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.eyeseetea.malariacare.layout.dashboard.deserializers;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;

import org.eyeseetea.malariacare.layout.dashboard.config.DashboardOrientation;

import java.io.IOException;

/**
 * Created by arrizabalaga on 16/03/16.
 */
public class DashboardOrientationDeserializer extends JsonDeserializer {
    @Override
    public Object deserialize(JsonParser p, DeserializationContext ctxt)
            throws IOException, JsonProcessingException {
        DashboardOrientation dashboardOrientation = DashboardOrientation.fromId(p.getValueAsString());
        if (dashboardOrientation != null) {
            return dashboardOrientation;
        }
        throw new JsonMappingException("'orientation' must be 'horizontal' or 'vertical'");
    }
}