Package com.coroptis.cubiculus.rest.mappers

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

/**
* 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.AjLegoBox;
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.JSONObject;
import com.sdicons.json.model.JSONValue;


public class JsonMapperAjLegoBox implements SimpleMapperHelper {

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

    @Override
    public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException {
  if (aValue.isObject()) {
      final JSONObject jsonObject = (JSONObject) aValue;
      final AjLegoBox out = new AjLegoBox();
      out.setAvgRating(Helper.getIntRequired(jsonObject, "avgRating",
        "AjLegoBox property avgRating was not found in json data"));
      out.setBoxNo(Helper.getStringRequired(jsonObject, "boxNo",
        "AjLegoBox property boxNo was not found in json data"));
      out.setDescription(Helper.getStringRequired(jsonObject, "description",
        "AjLegoBox property description was not found in json data"));
      out.setIdBoxImage(Helper.getIntRequired(jsonObject, "idBoxImage",
        "AjLegoBox property idBoxImage was not found in json data"));
      out.setIdBuildingInstruction(Helper.getIntRequired(jsonObject, "idBuildingInstruction",
        "AjLegoBox property idBuildingInstruction was not found in json data"));
      out.setIdLegoBox(Helper.getIntRequired(jsonObject, "idLegoBox",
        "AjLegoBox property idLegoBox was not found in json data"));
      out.setImage(Helper.getStringRequired(jsonObject, "image",
        "AjLegoBox property image was not found in json data"));
      out.setImageExtension(Helper.getStringRequired(jsonObject, "imageExtension",
        "AjLegoBox property imageExtension was not found in json data"));
      out.setLink(Helper.getStringRequired(jsonObject, "link",
        "AjLegoBox property link was not found in json data"));
      out.setName(Helper.getStringRequired(jsonObject, "name",
        "AjLegoBox property name was not found in json data"));
      out.setPieces(Helper.getIntRequired(jsonObject, "pieces",
        "AjLegoBox property pieces was not found in json data"));
      out.setPrice(Helper.getIntRequired(jsonObject, "price",
        "AjLegoBox property price was not found in json data"));
      out.setReleased(Helper.getIntRequired(jsonObject, "released",
        "AjLegoBox property released was not found in json data"));
      out.setSeparator(Helper.getIntRequired(jsonObject, "separator",
        "AjLegoBox property separator was not found in json data"));
      out.setTags(Helper.getStringRequired(jsonObject, "tags",
        "AjLegoBox property tags was not found in json data"));
      return out;
  }
  throw new MapperException("AjPropertyValue 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.JsonMapperAjLegoBox

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.