Deserialization of content into target class com.couchbase.client.java.json.JsonObject failed;

package com.mobileum.wcmodel.transformation;

import com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup;
import com.couchbase.client.core.deps.io.netty.channel.epoll.EpollEventLoopGroup;
import com.couchbase.client.core.deps.io.netty.util.concurrent.DefaultThreadFactory;
import com.couchbase.client.core.env.IoEnvironment;
import com.couchbase.client.core.env.TimeoutConfig;
import com.couchbase.client.core.error.CouchbaseException;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.env.ClusterEnvironment;
import com.couchbase.client.java.json.JsonArray;
import com.couchbase.client.java.json.JsonObject;
import com.couchbase.client.java.kv.LookupInSpec;
import com.couchbase.client.java.query.QueryOptions;
import com.couchbase.client.java.query.QueryProfile;
import com.couchbase.client.java.query.QueryResult;
import com.couchbase.client.java.query.QueryStatus;

import java.time.Duration;

import static com.couchbase.client.java.ClusterOptions.clusterOptions;


public class CouchbaseTest {

  public static void main(String[] args) {

 
    ClusterEnvironment environment = ClusterEnvironment.create();
    ClusterEnvironment.Builder envBuilder = environment.builder();

    envBuilder.timeoutConfig(TimeoutConfig.connectTimeout(Duration.ofMillis(60000)));
    EventLoopGroup group = new EpollEventLoopGroup(1, new DefaultThreadFactory("cb-io", true));
    envBuilder.ioEnvironment(IoEnvironment.kvEventLoopGroup(group));
    envBuilder.timeoutConfig(TimeoutConfig.queryTimeout(Duration.ofMillis(60000)));

    environment = envBuilder.build();

    Cluster cluster = Cluster.connect("", clusterOptions("", "").environment(environment));

    String query = "";

    QueryOptions qryOptions = QueryOptions.queryOptions().profile(QueryProfile.TIMINGS).metrics(true);
    QueryResult queryResult = cluster.query(query, qryOptions);

    if (queryResult.metaData().status() == QueryStatus.SUCCESS) {
      for (JsonObject row : queryResult.rowsAsObject()) {
        System.out.println("Found row: " + row);
      }
    }

  }
}

The above code threw error like below:

Exception in thread "main" com.couchbase.client.core.error.DecodingFailureException: Deserialization of content into target class com.couchbase.client.java.json.JsonObject failed; encoded = {"from_imsi":43,"hnwid":43,"to_imsi":232010110001902}
    at com.couchbase.client.java.codec.JacksonJsonSerializer.deserialize(JacksonJsonSerializer.java:135)
    at com.couchbase.client.java.query.QueryResult.rowsAs(QueryResult.java:90)
    at com.couchbase.client.java.query.QueryResult.rowsAsObject(QueryResult.java:78)
    at com.mobileum.wcmodel.transformation.CouchbaseTest.main(CouchbaseTest.java:59)   
 
Exception come at queryResult.rowsAsObject()

  • The error message is pretty clear about what the problem is. If you want us to help you debug, post the code of com.couchbase.client.java.json.JsonObject so we can see where the mismatch is.

    – 

Leave a Comment