Package com.coroptis.cubiculus.rest.mappers

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

/**
* 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 java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import com.coroptis.cubiculus.rest.model.AjPropertiesParams;
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.mapper.helper.impl.ObjectMapper;
import com.sdicons.json.model.JSONArray;
import com.sdicons.json.model.JSONObject;
import com.sdicons.json.model.JSONValue;


public class JsonMapperAjProperties implements SimpleMapperHelper {

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

    @Override
    public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException {
  if (aValue.isObject()) {
      JSONObject jsonObject = (JSONObject) aValue;
      // jsonObject.
      AjPropertiesParams out = new AjPropertiesParams();
      out.setYearRange((AjSelectionRange) JSONMapper.toJava(jsonObject.get("yearRange"),
        AjSelectionRange.class));
      out.setPriceRange((AjSelectionRange) JSONMapper.toJava(jsonObject.get("priceRange"),
        AjSelectionRange.class));
      out.setIdPropertyValues((List<Integer>) JSONMapper.toJava(
        jsonObject.get("idPropertyValues"), LinkedList.class));

      out.setIdPropertyValues(new ArrayList<Integer>());
      if (jsonObject.get("idPropertyValues") != null
        && jsonObject.get("idPropertyValues") instanceof JSONArray) {
    JSONArray array = (JSONArray) jsonObject.get("idPropertyValues");
    for (JSONValue jsonValue : array.getValue()) {
        out.getIdPropertyValues().add(
          (Integer) JSONMapper.toJava(jsonValue, Integer.class));
    }
      }
      return out;
  }
  throw new MapperException("BooleanMapper cannot map: " + aValue.getClass().getName());
    }

    @Override
    public JSONValue toJSON(Object aPojo) throws MapperException {
  ObjectMapper objectMapper = new ObjectMapper();
  return objectMapper.toJSON(aPojo);
    }

}
TOP

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

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.