简体   繁体   English

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

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

I want to convert an Observable object into a json object 我想将一个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);

This is what I'm trying to do but getting OnErrorNotImplementedException. 这是我正在尝试执行的操作,但遇到了OnErrorNotImplementedException。 Please someone help me on this. 请有人帮我。

The subscribe() method doesn't return the actual value of the subscription, it just triggers a subscription to that observable. subscription subscribe()方法不会返回订阅的实际值,它只会触发对该可观察对象的订阅。 Instead, you have to "listen" to the subscription and do your operation once it's done. 相反,您必须“收听”订阅并在完成后进行操作。 Something like this: 像这样:

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