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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:39:19+00:00 2026-06-10T12:39:19+00:00

I need to conver java array object to JSON, i am using jackson for

  • 0

I need to conver java array object to JSON, i am using jackson for this. I can only think that for every field name i have to iterate from the array which means i have to iterate the same array object for each field. Is there any efficient way of doing it?

        JsonGenerator jGenerator = jfactory.createJsonGenerator(out);
        jGenerator.writeStartObject();
        jGenerator.writeFieldName("images");
        jGenerator.writeStartArray();
        for(int i=0; i < topicBean.getTopicVOArray().length; i++){
            jGenerator.writeString(topicBean.getTopicVOArray()[i].getBody());
        }
        for(int i=0; i < topicBean.getTopicVOArray().length; i++){
            jGenerator.writeString(topicBean.getTopicVOArray()[i].getTopicGuid()());
        }
  • 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-10T12:39:21+00:00Added an answer on June 10, 2026 at 12:39 pm

    Depends on what you want the resulting json to look. Right now you’re going to get {"images":["bodystring","bodystring","guidstring","guidstring"]} but you could also make it {"images":["bodystring","guidstring","bodystring","guidstring"]} or, even better, {"images":[{"body":"bodystring","guid":"guidstring"},{"body":"bodystring","guid":"guidstring"}]}

    First solution:

    for(int i=0; i < topicBean.getTopicVOArray().length; i++){
        jGenerator.writeString(topicBean.getTopicVOArray()[i].getBody());
        jGenerator.writeString(topicBean.getTopicVOArray()[i].getTopicGuid()());
    }
    

    Second solution (object wrapper):

    for(int i=0; i < topicBean.getTopicVOArray().length; i++){
        jGenerator.writeStartObject();
        jGenerator.writeFieldName("body");
        jGenerator.writeString(topicBean.getTopicVOArray()[i].getBody());
        jGenerator.writeFieldName("guid");
        jGenerator.writeString(topicBean.getTopicVOArray()[i].getTopicGuid()());
        jGenerator.writeEndObject();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner in Java, I have array of bytes that I need
I need to convert a byte into an array of 4 booleans in Java.
I am using Jackson to serialize a JAXB annotated object into a map object.
In my Java Program, I need a byte array from a Hex String. So
Using Java, I have a class which retrieves a webpage as a byte array.
I have some .class files that I need to convert to .java so I
I've a problem with storing a Json object as a java object, I'm not
I want to convert a character array to a string object using the toString()
I have a byte array that can be of size 2,3 or 4. I
In Java how do you convert a ArrayList into a two dimensional array Object[][]?

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.