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 8935737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:03:43+00:00 2026-06-15T10:03:43+00:00

I have following JSON . And I am parsing it using Jackson Parser {

  • 0

I have following JSON. And I am parsing it using Jackson Parser

 {
  "code": 0,
  "response": {
    "pagination": {
        "page": 1,
        "limit": 20,
        "count": 5,
        "pageCount": 1
    },
   "random": [
      ....
     ]
  }
}

Now I have simple POJO classes created for various random object. I expect 3-4 different types of random object. So instead of creating different wrapper classes for different types of ‘random’ object I created a generic one

EDITED CLASS:

public class PaginatedResponse<E> {

   private Pagination pagination;
   private List<E> responseList;

   public Pagination getPagination() {
       return pagination;
   }

   public void setPagination(Pagination pagination) {
       this.pagination = pagination;
   }

   public List<E> getResponseList() {
       return responseList;
   }

   public void setResponseList(List<E> responseList) {
       this.responseList = responseList;
   }
}

Now For mapping it I used,

  JsonNode tree = mapper.readTree(response);
  TypeReference<PaginatedResponse<LocationParent>> ref = new TypeReference<PaginatedResponse<LocationParent>>() {   };
  PaginatedResponse<LocationParent> resp = mapper.convertValue(tree.get("response"), ref);

But i am not able to map responseList. I get the pagination object but the responseList is always null. Now how to dynamically provide property name for responseList.

Please help

  • 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-06-15T10:03:44+00:00Added an answer on June 15, 2026 at 10:03 am

    What you need for variable value type is handling for polymorphic types. Generic types alone won’t help, since deserialization side would not know what type to use.

    You can enable polymorphic type handling with annotation @JsonTypeInfo; but a problem in this particular case is that you want a List of things of arbitrary type — due to type-erasure, all Java Lists are really just List<Object>; there is no typing for elements.

    If it was me, I would probably sub-class PaginatedResponse and just add @JsonTypeInfo in base class, like:

    @JsonTypeInfo(...) // see javadocs for properties needed
    public abstract class PaginatedResponse<T> {
      public Pagination pagination;
      // .. and so on
    }
    
    public class PaginatedFooResponse<Foo> { }
    

    The reason to use sub-classing here is simply make it possible for deserializer to figure out element type, given type of response object. Response object will have type (PaginatedFooResposne), and from that type of elements is available.

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

Sidebar

Related Questions

I have the following scenario: I am parsing a JSON Response from a server
I have the following json code file named: sections.json { section1: { priority: 1,
I have the following JSON object: { response: { status: 200 }, messages: [
I have the following JSON Object: [{id:123,username:test}] I want to parse username using javascript
I have the following json parser. public class JSONParserThreaded extends AsyncTask<String, Integer, String> {
I have been using jackson to deserialize successfully json objects and arrays, but this
I am parsing JSON and I get the following error: I am using the
I have the following json object. var json1 = {00 : 00, 15 :
I have the following JSON String { name:Product, properties: { id: { type:number, description:Product
I have the following JSON string (from wikipedia http://en.wikipedia.org/wiki/JSON ) { name:Product, properties: {

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.