2021-01-07 11:34:56 +07:00

69 lines
2.0 KiB
Java

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<PapKebutuhanEdukasiVO, PapKebutuhanEdukasi> {
@Override
public PapKebutuhanEdukasi transferVOToModel(PapKebutuhanEdukasiVO vo, PapKebutuhanEdukasi model) {
if (null == model)
model = new PapKebutuhanEdukasi();
try {
String[] fieldsToInclude = null;
Map<String, Object> 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<PapKebutuhanEdukasiVO> transferListOfModelToListOfVO(List<PapKebutuhanEdukasi> models,
List<PapKebutuhanEdukasiVO> vos) {
if (null == vos)
vos = new ArrayList<PapKebutuhanEdukasiVO>();
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<String, Object> 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;
}
}