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

  • Home
  • SEARCH
  • 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 8069305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:59:05+00:00 2026-06-05T12:59:05+00:00

given the following json: { response: { totalProcessingTime: 271.0, resultSets: { products: { firstHit:

  • 0

given the following json:

{ "response": {
"totalProcessingTime": "271.0",
"resultSets": {
    "products": {
        "firstHit": "1",
        "lastHit": "10",
        "totalHits": "77",
        "hits": [ 
            {   
                "number": "1",
                "dmsubcategory": "TV, lyd og bilde",
                "collection": "tilbud",
                "title": "<b>TV</b> Panasonic 47 TX-LU 7ET5Y"
            },
            {   
                "number": "2",
                "dmsubcategory": "TV, lyd og bilde",
                "collection": "tilbud",
                "title": "<b>TV</b> Panasonic 47 TX-LU 7ET5Y"
            },
            {   
                "number": "3",
                "dmsubcategory": "TV, lyd og bilde",
                "collection": "tilbud",
                "title": "<b>TV</b> Panasonic 47 TX-LU 7ET5Y"
            }
            ]
        }
    }
  }
}

I’m using the following code to call jackson:

ObjectMapper mapper = new ObjectMapper();
SearchResult searchResult = mapper.readValue(new URL(jsonUrl + queryUrl), SearchResult.class);

I have ganerated POJOs for the whole hiearchy where the products class looks like:

public class Products {

public List<Hits> hits;
public String totalHits;

@JsonAnySetter
public void handleUnknown(String key, Object value) {
    // do something: put to a Map; log a warning, whatever
}

public List<Hits> getHits() {
    return hits;
}

public void setHits(List<Hits> hits) {
    this.hits = hits;
}

public String getTotalHits() {
    return totalHits;
}

public void setTotalHits(String totalHits) {
    this.totalHits = totalHits;
}

}

and the hits class:

public class Hits {

public String number;
public String title;

public String getNumber() {
    return number;
}
public void setNumber(String number) {
    this.number = number;
}
public String getTitle() {
    return title;
}
public void setTitle(String title) {
    this.title = title;
}

@JsonAnySetter
public void handleUnknown(String key, Object value) {
    // do something: put to a Map; log a warning, whatever
}

}

All the other properties are mapped correct, but not the list containing hits. It’s all empty. How can I map this to get it right?

Thanks!

  • 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-05T12:59:07+00:00Added an answer on June 5, 2026 at 12:59 pm

    You model is not compatible.

    In order to see what is going wrong, maybe it is a good idea to have some toStrings and you could easy see where the mapping is failing.

    You have a Object that needs to hold a property response, that needs to hold a property resultSets that needs to hold a property products that needs to hold hits.

    I implemented like this:

    GeneralResponse
      - Response
        - ResultSets
          - Products
            - Hits
              - number
              - title
    

    Please test following implementation:

    package snippet;
    
    public class GeneralResponse {
    
        private Response response;
    
        public Response getResponse() {
            return response;
        }
    
        public void setResponse(Response response) {
            this.response = response;
        }
    
        @Override
        public String toString() {
            return "GeneralResponse [response=" + response + "]";
        }
    
    }
    
    
    package snippet;
    
    public class ResultSets {
    
        private Products products;
    
        public Products getProducts() {
            return products;
        }
    
        public void setProducts(Products products) {
            this.products = products;
        }
    
        @Override
        public String toString() {
            return "ResultSets [products=" + products + "]";
        }
    
    }
    
    package snippet;
    
    import java.util.List;
    
    import org.codehaus.jackson.annotate.JsonAnySetter;
    
    public class Products {
    
        public List<Hits> hits;
        public String totalHits;
    
        @JsonAnySetter
        public void handleUnknown(String key, Object value) {
            // do something: put to a Map; log a warning, whatever
        }
    
        public List<Hits> getHits() {
            return hits;
        }
    
        public void setHits(List<Hits> hits) {
            this.hits = hits;
        }
    
        public String getTotalHits() {
            return totalHits;
        }
    
        public void setTotalHits(String totalHits) {
            this.totalHits = totalHits;
        }
    
        @Override
        public String toString() {
            return "Products [hits=" + hits + ", totalHits=" + totalHits + "]";
        }
    
    }
    
    
    package snippet;
    
    import org.codehaus.jackson.annotate.JsonAnySetter;
    
    public class Response {
    
        private ResultSets resultSets;
    
        public ResultSets getResultSets() {
            return resultSets;
        }
    
        public void setResultSets(ResultSets resultSets) {
            this.resultSets = resultSets;
        }
    
        @Override
        public String toString() {
            return "Response [resultSets=" + resultSets + "]";
        }
    
        @JsonAnySetter
        public void handleUnknown(String key, Object value) {
            // do something: put to a Map; log a warning, whatever
        }
    
    }
    
    
    
    package snippet;
    
    import org.codehaus.jackson.annotate.JsonAnySetter;
    
    public class Hits {
    
        public String number;
        public String title;
    
        public String getNumber() {
            return number;
        }
    
        public void setNumber(String number) {
            this.number = number;
        }
    
        public String getTitle() {
            return title;
        }
    
        public void setTitle(String title) {
            this.title = title;
        }
    
        @JsonAnySetter
        public void handleUnknown(String key, Object value) {
            // do something: put to a Map; log a warning, whatever
        }
    
        @Override
        public String toString() {
            return "Hits [number=" + number + ", title=" + title + "]";
        }
    
    }
    

    after all you can do something like:

        ObjectMapper om = new ObjectMapper();
        Object r = om.readValue(inputStream, GeneralResponse.class);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following JSON response from google maps. I've given two postcodes as
Given the following array of json objects: var items = [ {id:1, parentId:0, name:'item1'},
I've got the following object: $json = '{response: {status: {message: Success}, images: [{url: http://domain.com/images/0001.jpg},
Given the following JSON Date representation: \/Date(1221644506800-0700)\/ How do you deserialize this into it's
I get the following NSDictionary when I parse a JSON response from my server:
I have the following json-response from a script: [{title:Welkom bij Pica Plus!,url_title:welkom-bij-pica-plus,entry_id:36,channel_id:1,author_id:6,status:open,entry_date:1336650955000,edit_date:1337180757000,expiration_date:,answer_content:Beste [Leerling],\n\nWelkom bij
// given following array: $data = array( 0=>array( data=>object1, col=>array( 0=>array( data=>object2, col=>array( 0=>array(
Given following array: var arr = [undefined, undefined, 2, 5, undefined, undefined]; I'd like
Given following Statment: String query = "Select * from T_spareParts where SparePartPK IN (?
Given the following example (using JUnit with Hamcrest matchers): Map<String, Class<? extends Serializable>> expected

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.