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.TidurIstirahat; import com.jasamedika.medifirst2000.vo.TidurIstirahatVO; /** * Converter class between TidurIstirahat and TidurIstirahatVO * * @author Askur */ @Component public class TidurIstirahatConverter implements BaseVoConverter { public TidurIstirahat transferVOToModel(TidurIstirahatVO vo, TidurIstirahat model) { if (null == model) model = new TidurIstirahat(); 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, TidurIstirahat.class); } catch (Exception e) { e.printStackTrace(); } return model; } public List transferListOfModelToListOfVO(List models, List vos) { if (null == vos) vos = new ArrayList(); if (null == models) return vos; for (TidurIstirahat TidurIstirahat : models) { TidurIstirahatVO vo = new TidurIstirahatVO(); vo = transferModelToVO(TidurIstirahat, vo); vos.add(vo); } return vos; } @Override public TidurIstirahatVO transferModelToVO(TidurIstirahat model, TidurIstirahatVO vo) { if (null == vo) vo = new TidurIstirahatVO(); 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, TidurIstirahatVO.class); } catch (Exception e) { e.printStackTrace(); } return vo; } }