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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:22:35+00:00 2026-06-10T19:22:35+00:00

I am using Jackson parser in Java, and I want to generate JSON string

  • 0

I am using Jackson parser in Java, and I want to generate JSON string from the Java Object of the POJO in the following format. How can I do that?

{“TOTAL”:1,”CURRENTPAGE”:1,”TOTALRECORDS”:6,”ROWS”:[{“pagename”:”Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4}]}

If I do like the below thing then it is not working and giving me wrong output

    Tblselectablecolumnjqgrid selCol = new Tblselectablecolumnjqgrid();
    selCol.setPageid(4);
    selCol.setPagename("Test");
    selCol.setPagestatus("Test Status");

    selList.add(selCol);
    selList.add(selCol.clone());
    selList.add(selCol.clone());
    selList.add(selCol.clone());

    ObjectMapper om = new ObjectMapper();

    String writeValueAsString = om.writeValueAsString(selList);

    System.out.println("Result:    " + writeValueAsString);

    JsonFactory jsf = new JsonFactory();

    JsonTreeWriter tree = new JsonTreeWriter();

It gives me the below output

[{“pagename”:”Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4}]

What changes should I make in the code to get the desired output?

My POJO class

package com.pojo;

import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonCachable;

/**
 * @author bhavik.ambani
 *
 *         Useful for storing the current status of the grid in the table.
 */
public class Tblselectablecolumnjqgrid implements java.io.Serializable, Cloneable {

    private static final long serialVersionUID = 1L;

    @JsonProperty("id")
    private int pageid;

    private String pagename;

    private String pagestatus;

    public Tblselectablecolumnjqgrid() {
    }

    public Tblselectablecolumnjqgrid(int pageid, String pagename) {
        this.pageid = pageid;
        this.pagename = pagename;
    }

    public Tblselectablecolumnjqgrid(int pageid, String pagename,
            String pagestatus) {
        this.pageid = pageid;
        this.pagename = pagename;
        this.pagestatus = pagestatus;
    }

    public int getPageid() {
        return this.pageid;
    }

    public void setPageid(int pageid) {
        this.pageid = pageid;
    }

    public String getPagename() {
        System.out.println("Called Getter Method");
        return "Called getter Method : " + this.pagename;
    }

    public void setPagename(String pagename) {
        this.pagename = pagename;
    }

    public String getPagestatus() {
        return this.pagestatus;
    }

    public void setPagestatus(String pagestatus) {
        this.pagestatus = pagestatus;
    }

    @Override
    public Tblselectablecolumnjqgrid clone() throws CloneNotSupportedException {
        Tblselectablecolumnjqgrid selBean = (Tblselectablecolumnjqgrid) super
                .clone();
        selBean.setPageid(getPageid());
        selBean.setPagename(getPagename());
        selBean.setPagestatus(getPagestatus());

        return selBean;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + pageid;
        result = prime * result
                + ((pagename == null) ? 0 : pagename.hashCode());
        result = prime * result
                + ((pagestatus == null) ? 0 : pagestatus.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Tblselectablecolumnjqgrid other = (Tblselectablecolumnjqgrid) obj;
        if (pageid != other.pageid)
            return false;
        if (pagename == null) {
            if (other.pagename != null)
                return false;
        } else if (!pagename.equals(other.pagename))
            return false;
        if (pagestatus == null) {
            if (other.pagestatus != null)
                return false;
        } else if (!pagestatus.equals(other.pagestatus))
            return false;
        return true;
    }
}

Main method class

package com.jackson;

import java.io.IOException;
import java.util.ArrayList;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import com.pojo.Tblselectablecolumnjqgrid;

public class JacksonParser {

    public static void main(String args[]) throws JsonGenerationException,
            JsonMappingException, IOException, CloneNotSupportedException {

        ArrayList<Tblselectablecolumnjqgrid> selList = new ArrayList<Tblselectablecolumnjqgrid>();

        Tblselectablecolumnjqgrid selCol = new Tblselectablecolumnjqgrid();
        selCol.setPageid(4);
        selCol.setPagename("Test");
        selCol.setPagestatus("Test Status");

        selList.add(selCol);
        selList.add(selCol.clone());
        selList.add(selCol.clone());
        selList.add(selCol.clone());

        ObjectMapper om = new ObjectMapper();

        String writeValueAsString = om.writeValueAsString(selList);
        System.out.println("Result:    " + writeValueAsString);
    }
}

Expected Output

{“TOTAL”:1,”CURRENTPAGE”:1,”TOTALRECORDS”:6,”ROWS”:[{“pagename”:”Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4}]}

Output Getting

[{“pagename”:”Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4},{“pagename”:”Called getter Method : Called getter Method : Test”,”pagestatus”:”Test Status”,”id”:4}]

  • 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-10T19:22:37+00:00Added an answer on June 10, 2026 at 7:22 pm

    Write a wrapper like

    public class Wrapper {
      private int TOTAL;
      private int CURRENTPAGE;
      private int TOTALRECORDS;
      private List<Row> ROWS;
    
      //getters setters
    
    }
    
    public class Row {
      private String pagename;
      private String pagestatus;
      private int id;
    
      //getters setters
    }
    

    In your main class

    //populate Wrapper
    Wrapper wrap = new Wrapper();
    //set attributes and Rows
    ...
    String writeValueAsString = om.writeValueAsString(wrap);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Jackson I can able to convert the object to JSON @RequestMapping(value=getMessage.test, headers =
I have a class that needs to be deserialized from JSON using Jackson. The
How would you deserialize a JSON document to a POJO using Jackson if you
Im trying to pass an array from javascript to java servlet using Jackson, how
I want to use following xml webservice. www.musicbrainz.org/ws/2/artist/?query=artist:michael jackson which format is like below:
I'm using Jackson to serialize a custom class that implements Map<String, String> . But
I am using Jackson and a ContentNegotiatingViewResolver to return JSON from Spring controllers. When
I'm trying to return some JSON from my Spring webapp using Jackson and parse
Using Jackson, how can I have JSON serialized/deserialized by one application using one set
I'm using spring 3.1.2 and I need to parse a json object into POJO.

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.