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