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.PapKebutuhanEdukasi; import com.jasamedika.medifirst2000.vo.PapKebutuhanEdukasiVO; @Component public class PapKebutuhanEdukasiConverter implements BaseVoConverter { @Override public PapKebutuhanEdukasi transferVOToModel(PapKebutuhanEdukasiVO vo, PapKebutuhanEdukasi model) { if (null == model) model = new PapKebutuhanEdukasi(); 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, PapKebutuhanEdukasi.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 (PapKebutuhanEdukasi papKebutuhanEdukasi : models) { PapKebutuhanEdukasiVO vo = new PapKebutuhanEdukasiVO(); vo = transferModelToVO(papKebutuhanEdukasi, vo); vos.add(vo); } return vos; } @Override public PapKebutuhanEdukasiVO transferModelToVO(PapKebutuhanEdukasi model, PapKebutuhanEdukasiVO vo) { if (null == vo) vo = new PapKebutuhanEdukasiVO(); 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, PapKebutuhanEdukasiVO.class); } catch (Exception e) { e.printStackTrace(); } return vo; } }