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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:27:53+00:00 2026-06-09T19:27:53+00:00

From jsp through ajax cal I’m passing json string to server and I am

  • 0

From jsp through ajax cal I’m passing json string to server and I am converting to json object. How can I convert the jsonobject to a model class object in java?

In server I’m doing this:

 HttpServletRequest request = ServletActionContext.getRequest();
 String jsonData = request.getParameter("JsonData");
 JSONObject jsonDataObject = (JSONObject) JSONSerializer.toJSON( jsonData );

My model classes looks like this:

   public class Vehicles {

private List<Vehicle> vehicle;

public List<Vehicle> getVehicle() {
    return vehicle;
}

public void setVehicle(List<Vehicle> vehicle) {
    this.vehicle= vehicle;
}

    }

And

  public class Vehicle{
    private Integer vId;
   private String VName;
    private List<Department> department;
   //getters and setters;
    }

and

  public class Department{
    private Integer depId;
private String departmentName;
private List<Item> item;
   //getters and setters
   }

and

  public class Item{
  private Integer itemId;
  private String itemName;
  //getters and setters
   }

and I am getting jsonData String as

{"vehicles":[{"vehicle":[{"department":[{"Item":[{"itemId":31,"itemName":"c7"},{"itemId":32,"itemName":"c2"}],"depId":21,"departmentName":"d1"}],"vId":11,"VName":"aaa"},{"department":[{"Item":[{"itemId":33,"itemName":"c3"},{"itemId":34,"itemName":"c4"}],"depId":22,"departmentName":"d2"},{"Item":[{"itemId":36,"itemName":"c1"}],"depId":24,"departmentName":"d3"}],"vId":12,"VName":"bbbb"},{"department":[{"Item":[{"itemId":30,"itemName":"c6"},{"itemId":35,"itemName":"c5"}],"depId":23,"departmentName":"d4"}],"vId":13,"VName":"cccc"},{"department":[{"Item":[{"itemid":37,"itemName":"c8","status":0}],"depId":25,"departmentName":"d5"}],"vId":14,"VName":"ddd"}]}]}

How can I convert JSONObject jsonDataObject ( or String jsonData) to model class object(ie vehicles) in java?

  • 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-09T19:27:54+00:00Added an answer on June 9, 2026 at 7:27 pm

    use this..

      import org.codehaus.jackson.map.ObjectMapper;
      import org.json.JSONException;
      import org.json.JSONObject; 
    
    
    HttpServletRequest request = ServletActionContext.getRequest();
    Vehicles vehicles;
    String jsonData = request.getParameter("JsonData");
    jsonData = jsonData.substring(13, jsonData.length()-2);
    ObjectMapper mapper = new ObjectMapper();
    try{
        vehicles= mapper.readValue(jsonData, Vehicles.class);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a url in a JSP from a Map<String, Object> of
How can I call a servlet from jsp ? But in this case, I
I am trying to access an XML file from JSP on my Tomcat server.
I was told I could load a single component from a jsp file through
i am creating a pop up window through jsp and passing some selected values
I have a page which I'm converting from Velocity to JSP. I have some
I am generating input fields dynamically through jsp based on the data taken from
How to open One jsp from another through Struts ? For example, I have
I'm working on a jsp page that the user can browse through collection of
I'm sending multipart/mixed content message from JSP to servlets but when I used ServletFileUpload.isMultipartContent(request);

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.