-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Closed
Description
默认异常部分JSON.parseObject
ZookeeperDataSource<List<FlowRule>> flowRuleZkAutoDataSource = new ZookeeperDataSource<List<FlowRule>>(remoteAddress,
authInfoList, groupId, flowDataId,
new Converter<String, List<FlowRule>>() {
@Override
public List<FlowRule> convert(String source) {
return JSON.parseObject(source, new TypeReference<List<FlowRule>>() {
});
}
});
修改为jackson后能正常解析为对象
private void loadFlowRules(String remoteAddress, String path) {
ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new ZookeeperDataSource<>(remoteAddress, path,
source -> getFlowList(source));
FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
}
getFlowList
public List<FlowRule> getFlowList(String json) {
if (json == null || "".equals(json.trim())) {
return new ArrayList<>();
}
log.info("ZookeeperSentinelConfig getFlowList json {}", json);
List<FlowRule> list = null;
try {
list = objectMapper.readValue(json, new TypeReference<>() {
});
}catch (Exception e) {
log.error("ZookeeperSentinelConfig converter error {} ", e);
}
return list;
}
测试Json
[{"clusterConfig":{"fallbackToLocalWhenFail":true,"sampleCount":10,"strategy":0,"thresholdType":0,"windowIntervalMs":1000},"clusterMode":false,"controlBehavior":0,"count":1.0,"grade":1,"limitApp":"default","maxQueueingTimeMs":500,"resource":"com.aercool.sentinel.UserService:queryUser(java.lang.String)","strategy":0,"warmUpPeriodSec":10}]
Metadata
Metadata
Assignees
Labels
No labels