com.jd.blockchain.ledger.json.LedgerPrivilegeBitsetDeserializer Maven / Gradle / Ivy
package com.jd.blockchain.ledger.json;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONToken;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer;
import com.jd.blockchain.ledger.LedgerPermission;
import com.jd.blockchain.ledger.LedgerPrivilegeBitset;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.util.Map;
public class LedgerPrivilegeBitsetDeserializer extends JavaBeanDeserializer {
public static final LedgerPrivilegeBitsetDeserializer INSTANCE = new LedgerPrivilegeBitsetDeserializer(ParserConfig.global, LedgerPrivilegeBitset.class);
public LedgerPrivilegeBitsetDeserializer(ParserConfig config, Class> clazz) {
super(config, clazz);
}
@Override
public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
return (T) parser.parseObject(LedgerPrivilegeInfo.class).toPrivilegeBitset();
}
@Override
public Object createInstance(Map map, ParserConfig config) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
return JSON.parseObject(JSON.toJSONString(map), LedgerPrivilegeInfo.class).toPrivilegeBitset();
}
@Override
public int getFastMatchToken() {
return JSONToken.LBRACE;
}
/**
* {@link com.jd.blockchain.ledger.LedgerPrivilegeBitset} json 序列化后数据信息
*/
private static class LedgerPrivilegeInfo {
private int permissionCount;
private LedgerPermission[] privilege;
public int getPermissionCount() {
return permissionCount;
}
public void setPermissionCount(int permissionCount) {
this.permissionCount = permissionCount;
}
public LedgerPermission[] getPrivilege() {
return privilege;
}
public void setPrivilege(LedgerPermission[] privilege) {
this.privilege = privilege;
}
public LedgerPrivilegeBitset toPrivilegeBitset() {
LedgerPrivilegeBitset privilegeBitset = new LedgerPrivilegeBitset();
LedgerPermission[] privileges = getPrivilege();
for (int i = 0; i < permissionCount; i++) {
privilegeBitset.enable(privileges[i]);
}
return privilegeBitset;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy