RopSession.java
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cn.com.glsx.scrm.equity.rop;
import cn.com.glsx.scrm.equity.util.GsonUtils;
import cn.com.glsx.scrm.equity.util.ReflectUtils;
import cn.com.glsx.scrm.wechat.model.WechatUserInfo;
import com.rop.session.Session;
import java.io.Serializable;
import java.util.HashMap;
/**
* @Title: RopSession.java
* @Description:
* @author zengqi
* @date 2021年3月17日 下午12:36:01
* @version V1.0
* @Company: glsx.com.cn
* @Copyright Copyright (c) 2021
*/
public class RopSession extends HashMap<String, Serializable> implements Session {
private static final long serialVersionUID = 6779688165272652759L;
private boolean logout = false;
public <T> T get(String key, Class<T> clazz){
Object value = get(key);
if(value != null){
if(!isShareClass(clazz)){
return GsonUtils.convertObj(value.toString(), clazz);
}
return clazz.cast(value);
}
return null;
}
public boolean isLogout() {
return logout;
}
public void setLogout(boolean logout) {
this.logout = logout;
}
@Override
public Serializable put(String key, Serializable value) {
if(value != null){
if(!isShareClass(value.getClass())){
value = GsonUtils.toJson(value);
}
}
return super.put(key, value);
}
private boolean isShareClass(Class<?> clazz){
return (clazz == WechatUserInfo.class || ReflectUtils.isPrimitives(clazz));
}
}