Calling RPC API With Java Client

I am using upsource version 2.0.3682 and trying to call the json-rpc api through this rpc client but its failing in mapping the response object. Can you suggest possible fixes and guide to a couple of java examples that can make the api-integration smooth?

Below is the java client code

try {
    Map<String, String> headers = new HashMap<>(1);
    headers.put("Authorization", "Basic <encoded-credentials>");
    JsonRpcHttpClient client = new JsonRpcHttpClient(
            new URL("http://<servername>:8080/~rpc/getAllProjects"), headers);

    ProjectListDTO listDTO = client.invoke("getAllProjects", new Object[] {}, ProjectListDTO.class);
} catch (Throwable throwable) {

public class ProjectListDTO {
    private List<ProjectInfoDTO> project;

Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "project" (class com.myproject.upsource.ProjectListDTO), not marked as ignorable (0 known properties: ])
at [Source: N/A; line: -1, column: -1] (through reference chain: com.myproject.upsource.ProjectListDTO["project"])
     at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(
     at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(
     at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(
     at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(
     at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(
     at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(
     at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(
     at com.fasterxml.jackson.databind.ObjectMapper._readValue(
     at com.fasterxml.jackson.databind.ObjectMapper.readValue(
     at com.googlecode.jsonrpc4j.JsonRpcClient.readResponse(
     at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(
     ... 9 more


Comment actions Permalink


Why wouldn't you use Upsource java-library?

There are some API description available at http://<upsource_host>/~api_doc/index.html Does it help you?


Comment actions Permalink

Can you point me to the upsource java library? Can it act as a json-rpc api client?

There are some API description available at http://<upsource_host>/~api_doc/index.html Does it help you?

Yes I have been through the API documentation. It provides basic http call examples. I am looking for a java code sample that can help me to quickly get kick started.


Comment actions Permalink


We have prepared a java code sample for you -

Please let me know if it helps.

Comment actions Permalink

Thanks Artem. The sample really helped.


Please sign in to leave a comment.