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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:54:41+00:00 2026-05-31T03:54:41+00:00

Okay I have a JSON file and it has a set of objects that

  • 0

Okay I have a JSON file and it has a set of objects that I wish to unmarshal into array of objects.

An example of how the JSON file is laid out is:

{
"data":{
  "name":{
     "fName":"John",
     "lName":"Doe"
  },
  "name":{
     "fName":"James",
     "lName":"Dokes"
  }
 }
}

The full JSON file is a lot more complex than this, this is just a example of how it is laid out.

What I want to do is to take those names, and unmarshall them into an array of name objects so I can access each name object whenever I want.

The classes are set up as

Test Class

 private Data data;

public void setData(Data d) {
    data = d;
}

public Data getData() {
    return data;
}

public String toString() {
    return "" + data;
}

Data Class

 private Name name;

public void setName(Name n){
    name = n;
}


public Name getName(){
    return name;
}


public String toString(){
    return "Names " + name;
}

Then the Name class is just

public class Name {

private String fName;
private String lName;

 //Getter setters here

    public String toString(){
    return "\nFirstName: " + fName + "\nLastName: " + lName;
}

Then in the main class, I just do

 ObjectMapper mapper = new ObjectMapper();

    Test test = mapper.readValue(new File("C:\\JSON\\test.json"),
            Test.class);
    System.out.println(test);

Now this will print out

Names 
FirstName: James
LastName: Dokes

But it ignores the first name object, i.e. John Doe. What I want is to take each of these name objects and place them in an ArrayList, that way I can access the information, and display it whenever I want.

What am I doing wrong here? I tried changing the JSON file and making the names into an array, and then changing the code in the Data class and making Names an Array of object Names, but got an error saying

 Can not deserialize instance of Data out of START_ARRAY token

Would anyone be able to point me in the right direction here, as have tried many different solutions, but no success.

Thanks in advance for any help

EDIT:

Should my JSON look like this then

 {
"data":{
   "name":[
      {
         "fName":"John",
         "lName":"Doe"
      },
      {
        "fName":"test",
        "lName":"test2"
     }
   ]
 }
}
  • 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-05-31T03:54:42+00:00Added an answer on May 31, 2026 at 3:54 am

    What you posted isn’t really valid JSON as the data object has two keys with the same value name. Or rather, this JSON doesn’t represent an array of names as your title suggests it should.

    If the JSON data is meant to be a true JSON object, meaning that it is similar to a hashtable of names to values, then you should represent than in your Java class as a Map. But your Test class has a single Data field, which has a single Name field. One instance of Test cannot have more than one Name in this structure.

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

Sidebar

Related Questions

Okay, so I have a JSON array of image URLs. I want to load
Okay, so I have an AJAX function that gets a JSON encoded string from
Okay I have been racking my brain trying to build a JSON array from
Okay so I have a class that has 'weak typing' I.E. it can store
Okay I have a csv file that gets parsed and displayed. I want to
Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay I have a series of objects based on a base class which are
Okay i have two models: posts and comments. as you can think comments has
Okay, so here's the issue. I have two apps that need to package up
I am using RestEasy to marchal entities to JSON. That works okay but somehow

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.