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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:45:46+00:00 2026-06-02T00:45:46+00:00

I have json which I am trying to parse using Jackson. JSON looks as

  • 0

I have json which I am trying to parse using Jackson. JSON looks as –

coupons: {
  1: {
     title: "Mode von",
     description: "",
     type: "offer",
     code: "-",
     expiry: "0000-00-00",
     link: ""
  },    
  2: {
     title: "Prime 1",
     description: "",
     type: "offer",
     code: "-",
     expiry: "0000-00-00",
     link: "http://test.com/"
  }
}

The number of coupons are not constant here and would vary from response to response.
My dilemma is to create corresponding java class which could hold such object.

I tried with Map as –

public class Coupons {
   Map<String, String>coupons = new HashMap<String, String>();
   public Map<String, String> getCoupons() {
      return coupons;
   }
}

But –

System.out.println(coupons.getCoupons().get("type"));
System.out.println(coupons.getCoupons().get("code"));

always get me null. What would be right java class for this json?

  • 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-02T00:45:47+00:00Added an answer on June 2, 2026 at 12:45 am

    your first level of keys are the index numbers 1, 2, 3, etc.
    so in order to get the type and code, you have to specificy the key.

    you could do this:

    var coupons = coupons.getCoupons(); //<--breakpoint to see if this is really populated.
    foreach( String key in coupons.Keys ){ //<- pseudo code, iterate over keys  
      var obj = coupons.get(key);
      var type = obj.get("type");
      etc..
    }
    

    hope this helps you move on

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

Sidebar

Related Questions

I'm trying to parse some JSON in Grails using the grails.converters.JSON library. I have
I have a JSON which I get from web application. I try this parse
I have a JSON which looks like this { secInfo: [ { loginResult: 1,
I have parse json file which contain more than hundred location name, there latitude
I have been trying to load images which are in database(on local phone) .JSON
I am trying to parse JSON of the following form using aeson {field:{name:...}} or
I'm trying to parse some JSON using the JSon.Net library. The documentation seems a
I have this JSON (which validates according to JSONLint ): [ { "BugCount":"2", "BugTitle":"C:\\INETPUB\\WWWROOT\\CLUBREADY2\\TRAINERS\\../Connections/LTC.asp",
I have this json which populates my collection ( TableListCollection ) of models (
We have a JSON response which can contain null values (e.g. { myValue: null

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.