Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AerCool opened this issue Oct 27, 2020 · 4 comments

Comments

@AerCool
Copy link

AerCool commented Oct 27, 2020

默认异常部分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}]
@AerCool AerCool changed the title sentinel-datasource-zookeeper的测试类中,Json转对象会丢失resource字段,切换成jackson后正常 1.8.0 sentinel-datasource-zookeeper的测试类中,Json转对象会丢失resource字段,切换成jackson后正常 Oct 27, 2020
@jasonjoo2010
Copy link
Collaborator

确认一下fastjson版本,需要1.2.12以上,见 #1377

另外未来可能会有多json适配支持,见 #1739

@AerCool
Copy link
Author

AerCool commented Oct 29, 2020

yeah. useful.

@jasonjoo2010
Copy link
Collaborator

yeah. useful.

So was it solved after checking the correct fastjson?

@jasonjoo2010
Copy link
Collaborator

Close due to no further response.
If any more questions please feel free to reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants