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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:12:27+00:00 2026-06-11T19:12:27+00:00

I have some simple data in XML format which I need to convert to

  • 0

I have some simple data in XML format which I need to convert to JSON and also be able to convert the JSON back into the same XML string. But I’m having problems with doing this using existing jackson (version 2.0.6) libraries.

Here’s an example of XML data with similar structure

<channels>
  <channel>A</channel>
  <channel>B</channel>
  <channel>C</channel>
</channels>

To be able to convert this back to the original XML, I’d like the JSON to look something like this

{
  "channels": {
    "channel": [
      "A",
      "B",
      "C"
    ]
  }
}

However jackson gives me

{"channel":"C"}

The root element name is not preserved and instead og creating array of channels, the last one overwrites the previous ones.

Looking at the source code of com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer I found that the library doesn’t support this, but allows for overriding and changing the behavior.

/**
 * Method called when there is a duplicate value for a field.
 * By default we don't care, and the last value is used.
 * Can be overridden to provide alternate handling, such as throwing
 * an exception, or choosing different strategy for combining values
 * or choosing which one to keep.
 *
 * @param fieldName Name of the field for which duplicate value was found
 * @param objectNode Object node that contains values
 * @param oldValue Value that existed for the object node before newValue
 *   was added
 * @param newValue Newly added value just added to the object node
 */
protected void _handleDuplicateField(String fieldName, ObjectNode objectNode,
                                     JsonNode oldValue, JsonNode newValue)
    throws JsonProcessingException
{
    // By default, we don't do anything
    ;
}

So my questions are

  1. Has anyone written a custom deserializer to support this feature? Or is there another way to work around this.
  2. How do I preserve the root element name?

Below is a test example

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
public class Test {
  public static void main(String[] args) throws Exception {
    String xml="<channels><channel>A</channel><channel>B</channel><channel>C</channel></channels>";

    XmlMapper xmlMapper = new XmlMapper();
    JsonNode node=xmlMapper.readValue(xml,JsonNode.class);
    System.out.println(node.toString());
  }
}
  • 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-11T19:12:28+00:00Added an answer on June 11, 2026 at 7:12 pm

    What really matters here are your classes — just showing XML in itself does not give enough information to know what is going on.

    I suspect that you will need Jackson 2.1 (once it gets released in a week or two), since it finally supports “unwrapped Lists” correectly. Prior to this, only “wrapped” Lists work correctly.

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

Sidebar

Related Questions

I have a simple jasper report which shows some data from database. The jasper
I need to create a storage file format for some simple data in a
Let's say I have some simple data y = [[datetime.datetime( 2012,1,1,1,1), 2.1], [datetime.datetime( 2012,1,1,1,2),
I have some data in .cvs. I would like to make a simple barplot
I'm new to WCF data services. I have a quite simple data model. Some
i have a simple template that i populate with some data then im trying
Say you have a simple class with some storage data structure (list, vector, queue,
I'd like some advice on which format to use for transmitting data over TCP.
I have some data in c#, and I want to put this data into
I have some simple SOAP client to get data from WSDL and display it.

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.