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

75 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.dao.custom.base.impl.FindConverterDao;
import com.jasamedika.medifirst2000.entities.RiwayatPendidikan;
import com.jasamedika.medifirst2000.vo.RiwayatPendidikanVO;
/**
*
* @author shakato
*/
@Component
public class RiwayatPendidikanConverter extends FindConverterDao implements
BaseVoConverter<RiwayatPendidikanVO, RiwayatPendidikan> {
public RiwayatPendidikan transferVOToModel(RiwayatPendidikanVO vo, RiwayatPendidikan model) {
if (null == model)
model = new RiwayatPendidikan();
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, RiwayatPendidikan.class);
} catch (Exception e) {
e.printStackTrace();
}
return model;
}
public List<RiwayatPendidikanVO> transferListOfModelToListOfVO(List<RiwayatPendidikan> models,
List<RiwayatPendidikanVO> vos) {
if (null == vos)
vos = new ArrayList<RiwayatPendidikanVO>();
if (null == models)
return vos;
for (RiwayatPendidikan model : models) {
RiwayatPendidikanVO vo = new RiwayatPendidikanVO();
transferModelToVO(model, vo);
vos.add(vo);
}
return vos;
}
public RiwayatPendidikanVO transferModelToVO(RiwayatPendidikan model, RiwayatPendidikanVO vo) {
if (null == vo)
vo = new RiwayatPendidikanVO();
try {
String[] fieldsToInclude = null;
Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getName());
Gson gson = new Gson();
String json = gson.toJson(serialized);
vo = gson.fromJson(json, RiwayatPendidikanVO.class);
} catch (Exception e) {
e.printStackTrace();
}
return vo;
}
}