Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6019809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:28:29+00:00 2026-05-23T03:28:29+00:00

I am trying to deserialise a JSON-RPC object with Jackson. The format of JSON-RPC

  • 0

I am trying to deserialise a JSON-RPC object with Jackson. The format of JSON-RPC is :

{ “result”: “something”, “error”: null, “id”: 1}

In my case the result property is an generic Object.

I have a class for deserilising the response:

public class JsonRpcResponse {

private Object result;
private JsonRpcError error;
private int id;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public JsonRpcError getError() {
    return error;
}

public void setError(JsonRpcError error) {
    this.error = error;
}

public Object getResult() {
    return result;
}

public void setResult(Object result) {
    this.result = result;
}

}

I can get the response object with:

 JsonRpcResponse jsonResp = mapper.readValue(response, JsonRpcResponse.class);

I want to have a generic method that deserializes this result object by passing to the method the type of the object (or the class if you want) that is going to be deserialized to. This way I can pass any type of object depending of the response I expect.

For example, I have this class with two properties:

public class JsonEventProperties {

private String conditon;
private String usage;

public JsonEventProperties(String condition, String usage) {
    this.conditon = condition;
    this.usage = usage;
}

public JsonEventProperties() {
    throw new UnsupportedOperationException("Not yet implemented");
}

public String getConditon() {
    return conditon;
}

public void setConditon(String conditon) {
    this.conditon = conditon;
}

public String getUsage() {
    return usage;
}

public void setUsage(String usage) {
    this.usage = usage;
}    

}

The result object inside the response for the above case will be:

"result": {"condition":"test","usage":"optional"}

I tried:

mapper.readValue(result,objectClass)

where result is a JsonNode intance of the result (Which for some reason is a LinkedHashMap) and objectClass the class I want it to deserialize to. But this is not working.

I busted my head all day with different ways of doing this but I probably do not understand who Jackson works.

Can anyone help me with this?

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:28:30+00:00Added an answer on May 23, 2026 at 3:28 am

    I understand the original question to be asking about polymorphic deserialization of the “result” object.

    Jackson now has a built-in mechanism available for this, using the @JsonTypeInfo and @JsonSubTypes annotations. (ObjectMapper has methods available as alternatives to using the annotations.) Further information is available in the official docs at http://wiki.fasterxml.com/JacksonPolymorphicDeserialization. Also, I posted a few use examples of this at http://programmerbruce.blogspot.com/2011/05/deserialize-json-with-jackson-into.html.

    However, if you’re stuck deserializing JSON that, in the target object, does not have an element that identifies the type by some name, then you’re stuck with custom deserialization, where you’ll have to determine based on some object content what the type should be. One of the last examples in the same blog posted I linked above demonstrates this approach, using the existence of particular JSON elements in the target object to determine the type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to deserialize json to an object model where the collections are represented
I am trying to serialize/deserialize JSON in Android using GSON. I have two classes
I'm trying to deserialize object derived from Exception class: [Serializable] public class Error :
I'm trying to deserialize JSON into a custom object but all my properties are
I have the following JSON: {workspace: { name:Dallas, dataStores:http://.....:8080/geoserver/rest/workspaces/Dallas/datastores.json, coverageStores:http://.....:8080/geoserver/rest/workspaces/Dallas/coveragestores.json, wmsStores:http://....:8080/geoserver/rest/workspaces/Dallas/wmsstores.json}} And I´m trying
I am trying to deserialize a Json object that I am getting from the
I'm trying to deserialize some JSON with Jersey/Jackson in Java. Here is an example
I am trying to deserialize the following JSON, but I really have no idea
I'm trying to deserialize JSON in this format: { data: [ { installed: 1,
I'm trying to deserialize JSON in this format: { data: [ { installed: 1,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.