forked from fanruan/demo-tabledata-transfer
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.5 KiB
44 lines
1.5 KiB
4 years ago
|
package com.fr.plugin.demo.dataset.transfer;
|
||
|
|
||
|
import com.fr.data.impl.Connection;
|
||
|
import com.fr.decision.fun.impl.AbstractTransferConnectionManagerProvider;
|
||
|
import com.fr.third.fasterxml.jackson.core.type.TypeReference;
|
||
|
import com.fr.third.fasterxml.jackson.databind.ObjectMapper;
|
||
|
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* @author lidongy
|
||
|
* @version 10.0
|
||
|
* Created by lidongy on 2021/3/4
|
||
|
*/
|
||
|
public class DemoConnectionTransferManager extends AbstractTransferConnectionManagerProvider<DemoConnection> {
|
||
|
|
||
|
private static final String FIELD_HOST = "host";
|
||
|
private static final String FIELD_USERNAME = "username";
|
||
|
|
||
|
@Override
|
||
|
public Class<? extends Connection> getConnectionClass() {
|
||
|
return DemoConnection.class;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String serialize(DemoConnection demoConnection) throws Exception {
|
||
|
Map<String, Object> map = new HashMap<>();
|
||
|
map.put(FIELD_HOST, demoConnection.getHost());
|
||
|
map.put(FIELD_USERNAME, demoConnection.getUsername());
|
||
|
return new ObjectMapper().writeValueAsString(map);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public DemoConnection deserialize(String str) throws Exception {
|
||
|
Map<String, Object> map = new ObjectMapper().readValue(str, new TypeReference<Map<String, Object>>() {
|
||
|
});
|
||
|
DemoConnection demoConnection = new DemoConnection();
|
||
|
demoConnection.setHost((String) map.get(FIELD_HOST));
|
||
|
demoConnection.setUsername((String) map.get(FIELD_USERNAME));
|
||
|
return demoConnection;
|
||
|
}
|
||
|
}
|