Skip to content

1.8.0 sentinel-datasource-zookeeper的测试类中,Json转对象会丢失resource字段,切换成jackson后正常 #1824

@AerCool

Description

@AerCool

默认异常部分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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions