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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:57:03+00:00 2026-06-15T04:57:03+00:00

My question is what’s the best way to convert multiple lists back to back

  • 0

My question is what’s the best way to convert multiple lists back to back into a single JsonArray. The lists are coming on the fly, so I don’t want to or I can’t have all the lists(list1 – listn) merged in a big list, then use Jackson to write the merged list to a JsonArray.

Convert

ArrayList<Event> list1 = new ArrayList<Event>();
    list1.add(new Event("a1","a2"));
    list1.add(new Event("b1","b2"));

ArrayList<Event> list2 = new ArrayList<Event>();
    list2.add(new Event("c1","c2"));
    list2.add(new Event("d1","d2"));
......
......listn 

To a single jsonArray:

[
{"field1":"a1", "field2":"a2"},
{"field1":"b1", "field2":"b2"},
{"field1":"c1", "field2":"c2"},
{"field1":"d1", "field2":"d2"},
......
{"field1":"n1", "field2":"n2"}
]
  • 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-15T04:57:05+00:00Added an answer on June 15, 2026 at 4:57 am

    At the end of the day, I found out that there is no such way in Jackson allowing you directly write two lists back to back into a JsonArray. You can either implement JsonGenerator with your own implementation writeStartArray() writeEndArray() OR even easier, you can just define the startArray and endArray, and construct the jsonArray by yourself

    private static final String JSON_ARRAY_START = "[" + LINE_BREAK;
    private static final String JSON_ARRAY_COMMA = "," + LINE_BREAK;
    private static final String JSON_ARRAY_END = LINE_BREAK+ "]";
    

    so code will roughly look like:

    write(JSON_ARRAY_START)
    foreach list1
        use objectMapper write every Event object
        write(JSON_ARRAY_COMMA)
    foreach list2
        use objectMapper write every Event object
        if it's not the last element in the list, write(JSON_ARRAY_COMMA)
    write(JSON_ARRAY_END)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
Question: I want to test an if statement in PostgreSQL: IF (SELECT COUNT(*) FROM
Question: What is the standard method for accessing back end data, which logon should
Question says it all ... is there a way to generate more than 50
Question: What is the correct syntax to use when selecting a column value into
Question Does anyone know of a way to round a float to the nearest
Question: I want to untar a tarfile which has many tar files within itself
Question is : how to add any event in calender? i want to make
Question : Is there a simple way to print out an array in Ruby
I don't have much knowledge about the IPv6 protocol, so sorry if the question

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.