123456789101112131415161718192021222324252627 |
- package in.ocsf.these.days.app.state;/* kpmy 20.02.2017 */
- import org.apache.commons.beanutils.BeanMap;
- import org.springframework.statemachine.StateMachineContext;
- import java.util.HashMap;
- import java.util.Map;
- public interface BeanMapPersist {
- default Map<String, Object> toMap(StateMachineContext context) throws Exception {
- Map<String, Object> data = new HashMap<>(new BeanMap(context));
- data.replace("class", ((Class) data.get("class")).getCanonicalName());
- return data;
- }
- default StateMachineContext fromMap(Map<String, Object> data) throws Exception {
- if (data != null) {
- data.replace("class", Class.forName((String) data.get("class")));
- BeanMap beanMap = new BeanMap();
- beanMap.putAll(data);
- return (StateMachineContext) beanMap.getBean();
- } else {
- return null;
- }
- }
- }
|