Package com.coroptis.cubiculus.rest.mappers

Source Code of com.coroptis.cubiculus.rest.mappers.JsonMapperAjSelectionRange

/**
* Copyright 2012 cubiculus.com
*
*    Licensed under the Apache License, Version 2.0 (the "License");
*    you may not use this file except in compliance with the License.
*    You may obtain a copy of the License at
*
*        http://www.apache.org/licenses/LICENSE-2.0
*
*    Unless required by applicable law or agreed to in writing, software
*    distributed under the License is distributed on an "AS IS" BASIS,
*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*    See the License for the specific language governing permissions and
*    limitations under the License.
*/
package com.coroptis.cubiculus.rest.mappers;

import com.coroptis.cubiculus.rest.model.AjSelectionRange;
import com.sdicons.json.mapper.JSONMapper;
import com.sdicons.json.mapper.MapperException;
import com.sdicons.json.mapper.helper.SimpleMapperHelper;
import com.sdicons.json.model.JSONObject;
import com.sdicons.json.model.JSONString;
import com.sdicons.json.model.JSONValue;


public class JsonMapperAjSelectionRange implements SimpleMapperHelper {

    @Override
    public Class getHelpedClass() {
  return AjSelectionRange.class;
    }

    @Override
    public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException {
  if (aValue.isObject()) {
      final JSONObject jsonObject = (JSONObject) aValue;
      final AjSelectionRange out = new AjSelectionRange();
      final JSONValue fromJsonValue = jsonObject.get("from");
      if (fromJsonValue == null) {
    out.setFrom(-1);
      } else {
    out.setFrom((Integer) JSONMapper.toJava(fromJsonValue, Integer.class));
      }
      final JSONValue toJsonValue = jsonObject.get("to");
      if (toJsonValue == null) {
    out.setTo(Integer.MAX_VALUE);
      } else {
    out.setTo((Integer) JSONMapper.toJava(jsonObject.get("to"), Integer.class));
      }
      return out;
  }
  throw new MapperException("BooleanMapper cannot map: " + aValue.getClass().getName());
    }

    @Override
    public JSONValue toJSON(Object aPojo) throws MapperException {
  AjSelectionRange range = (AjSelectionRange) aPojo;
  final JSONObject out = new JSONObject();
  out.getValue().put("from", new JSONString(String.valueOf(range.getFrom())));
  out.getValue().put("to", new JSONString(String.valueOf(range.getTo())));
  return out;
    }

}
TOP

Related Classes of com.coroptis.cubiculus.rest.mappers.JsonMapperAjSelectionRange

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.