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