package com.jasamedika.medifirst2000.converter; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.springframework.stereotype.Component; import com.google.gson.Gson; import com.jasamedika.medifirst2000.converter.base.BaseVoConverter; import com.jasamedika.medifirst2000.entities.CheckOutOperation; import com.jasamedika.medifirst2000.vo.CheckOutOperationVO; @Component public class CheckOutOperationConverter implements BaseVoConverter { @Override public CheckOutOperation transferVOToModel(CheckOutOperationVO vo, CheckOutOperation model) { if (null == model) model = new CheckOutOperation(); try { String[] fieldsToInclude = null; Map serialized = vo.serialize(fieldsToInclude,vo.getClass().getName()); Gson gson = new Gson(); String json = gson.toJson(serialized); model = gson.fromJson(json, CheckOutOperation.class); } catch (Exception e) { e.printStackTrace(); } return model; } @Override public List transferListOfModelToListOfVO(List models, List vos) { if (null == vos) vos = new ArrayList(); if (null == models) return vos; for (CheckOutOperation checkOutOperation : models) { CheckOutOperationVO vo = new CheckOutOperationVO(); vo=transferModelToVO(checkOutOperation, vo); vos.add(vo); } return vos; } @Override public CheckOutOperationVO transferModelToVO(CheckOutOperation model, CheckOutOperationVO vo) { if (null == vo) vo = new CheckOutOperationVO(); try { String[] fieldsToInclude = null; Map serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName()); Gson gson = new Gson(); String json = gson.toJson(serialized); vo = gson.fromJson(json, CheckOutOperationVO.class); } catch (Exception e) { e.printStackTrace(); } return vo; } public CheckOutOperationVO transferModelToVOCustom(CheckOutOperation model, CheckOutOperationVO vo,String[] fieldsToInclude) { if (null == vo) vo = new CheckOutOperationVO(); try { Map serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName()); Gson gson = new Gson(); String json = gson.toJson(serialized); vo = gson.fromJson(json, CheckOutOperationVO.class); } catch (Exception e) { e.printStackTrace(); } return vo; } }