繁体   English   中英

如何转换一个可观察的 <String> 到JSON

[英]How to convert an Observable<String> to JSON

我想将一个Observable对象转换为一个json对象

ObjectMapper mapper = new ObjectMapper();
    Observable<String> response = accountSearchService.searchAccount(paramMap, "", 0, 1);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    AccountSearchResult resultDto = mapper.convertValue(response.subscribe().toString(), AccountSearchResult.class);

这是我正在尝试执行的操作,但遇到了OnErrorNotImplementedException。 请有人帮我。

subscription subscribe()方法不会返回订阅的实际值,它只会触发对该可观察对象的订阅。 相反,您必须“收听”订阅并在完成后进行操作。 像这样:

ObjectMapper mapper = new ObjectMapper();
    Observable<String> response = accountSearchService.searchAccount(paramMap, "", 0, 1);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    response.subscribe(stringValue -> {
            AccountSearchResult resultDto = mapper.convertValue(stringValue, AccountSearchResult.class);
        }, throwable -> {
            //onError
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM