简体   繁体   中英

Error on getting JSON data from Couchbase DB in JAVA Restful API

Error on getting JSON data from Couchbase DB in JAVA Restful API.

I am trying to retrieve JSON data from Couchbase DB and return it through an API.

Error :

"HTTP Status 500 - java.lang.ClassCastException: java.lang.String cannot be cast to com.couchbase.client.java.document.JsonDocument"

Code:

@Override
    public JsonDocument getProduct(String productId)
            throws URISyntaxException, IOException, InterruptedException, Exception {
        JsonDocument response = null;
        CouchbaseConnectionManager couchbaseConnectionManager = new CouchbaseConnectionManager();
        response = (JsonDocument) couchbaseConnectionManager.getCouchbaseClient().get(productId);
        return response;
    }

Could you please help.

Thanks

Looks like the API returns a string and you are casting to a JsonDocument. You could take the return as a string and then use org.json or other Json helpers to convert to JSON

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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