91 lines
2.4 KiB
Java
91 lines
2.4 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.CheckOutOperation;
|
|
import com.jasamedika.medifirst2000.vo.CheckOutOperationVO;
|
|
|
|
@Component
|
|
public class CheckOutOperationConverter implements BaseVoConverter<CheckOutOperationVO, CheckOutOperation> {
|
|
|
|
|
|
@Override
|
|
public CheckOutOperation transferVOToModel(CheckOutOperationVO vo, CheckOutOperation model) {
|
|
if (null == model)
|
|
model = new CheckOutOperation();
|
|
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, CheckOutOperation.class);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return model;
|
|
}
|
|
|
|
@Override
|
|
public List<CheckOutOperationVO> transferListOfModelToListOfVO(List<CheckOutOperation> models, List<CheckOutOperationVO> vos) {
|
|
|
|
if (null == vos)
|
|
vos = new ArrayList<CheckOutOperationVO>();
|
|
|
|
if (null == models)
|
|
return vos;
|
|
|
|
for (CheckOutOperation checkOutOperation : models) {
|
|
CheckOutOperationVO vo = new CheckOutOperationVO();
|
|
vo=transferModelToVO(checkOutOperation, vo);
|
|
vos.add(vo);
|
|
}
|
|
|
|
return vos;
|
|
}
|
|
|
|
@Override
|
|
public CheckOutOperationVO transferModelToVO(CheckOutOperation model, CheckOutOperationVO vo) {
|
|
if (null == vo)
|
|
vo = new CheckOutOperationVO();
|
|
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, CheckOutOperationVO.class);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return vo;
|
|
}
|
|
|
|
public CheckOutOperationVO transferModelToVOCustom(CheckOutOperation model, CheckOutOperationVO vo,String[] fieldsToInclude) {
|
|
if (null == vo)
|
|
|
|
vo = new CheckOutOperationVO();
|
|
|
|
try {
|
|
Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName());
|
|
Gson gson = new Gson();
|
|
String json = gson.toJson(serialized);
|
|
vo = gson.fromJson(json, CheckOutOperationVO.class);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return vo;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|