我想将可观察对象转换为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);
这就是我正在尝试做的事情,但得到OnErrorNotImplementException。 请有人帮我解决这个问题。
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
});