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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:21:48+00:00 2026-06-08T21:21:48+00:00

Similar to this question asked on Stackoverflow, using JAXB to represent a list as

  • 0

Similar to this question asked on Stackoverflow, using JAXB to represent a list as the root element, I have the same issue. Though the solution outlined in the answer doesn’t work for me.

Note: I am using the Jackson fasterxml lib for doing the mappings.

Essentialy I am consuming some XML from an API (the recurly api). One of the messages returned by the API has the root element as a list, a demonstration is shown below:

<plans type="array">
    <plan href="...">
    ...
    </plan>
    <plan href="...">
    ...
    </plan>
</plans>

I created the following Java class + JAXB annotations to capture the above:

@XmlRootElement(name = "plans")
public class Plans extends RecurlyObject {

    @XmlElement(name = "plan", type = Plan.class)
    private List<Plan> plans;

    public List<Plan> getPlans() { return this.plans; }

    public void setPlans(final List<Plan> plans) { this.plans = plans; }
    ...
}

This doesn’t work. The docs & articles I have read all demo the above using Strings rather than custom types for the elements of the list.

Running the above generates the following error:

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value
of type [simple type, class com.ning.billing.recurly.model.Plan] from JSON String; no
single-String constructor/factory method (through reference chain:
com.ning.billing.recurly.model.Plans[“plan”])

I also tried the following – but generates a similar issue:

@XmlRootElement(name = "plans")
public class Plans extends RecurlyObject {
    @XmlTransient
    public static final String PLANS_RESOURCE = "/plans";

    @XmlElementWrapper(name = "plans")
    @XmlElement(name = "plan", type = Plan.class)
    private List<Plan> plans;

    public List<Plan> getPlans() { return this.plans; }

    public void setPlans(final List<Plan> plans) { this.plans = plans; }
    ...
}

The only way I can it to not error is if I create a ctor on my Plan class that takes a String. But then my List<Plan> is a list of Plan objects, one for every sub node of all of the Plans 🙁

BTW – the Plan Java class works fine – I use it to receive individual Plan messages from other API calls.

So, any ideas how to correctly map a root element which is a list of things other than Strings into a Java object using JAXB?

Cheers

UPDATE

The following solution was provided by Pierre outside of stackoverflow.

It is possible to get this to work with Jackson see the following code:

@XmlRootElement(name = "plans")
public class Plans extends RecurlyObjects<Plan> {
}

The important details to note is extends RecurlyObjects<Plan>. RecurlyObjects is essentially an ArrayList.

@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class RecurlyObjects<T extends RecurlyObject> extends ArrayList<T> {
}

This now works fine.

  • 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-08T21:21:49+00:00Added an answer on June 8, 2026 at 9:21 pm

    By default you should annotate the property. I’ve simplified your mapping where possible.

    package forum11748159;
    
    import java.util.List;
    import javax.xml.bind.annotation.*;
    
    @XmlRootElement
    public class Plans extends RecurlyObject {
    
        private List<Plan> plans;
    
        @XmlElement(name = "plan")
        public List<Plan> getPlans() { return this.plans; }
    
        public void setPlans(final List<Plan> plans) { this.plans = plans; }
    
    }
    

    If you want to annotate the fields you need to add the @XmlAccessorType(XmlAccessType.FIELD) annotation to your class:

    package forum11748159;
    
    import java.util.List;
    import javax.xml.bind.annotation.*;
    
    @XmlRootElement(name = "plans")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Plans extends RecurlyObject {
    
        @XmlElement(name = "plan")
        private List<Plan> plans;
    
        public List<Plan> getPlans() { return this.plans; }
    
        public void setPlans(final List<Plan> plans) { this.plans = plans; }
    
    }
    

    Note: I am using the Jackson fasterxml lib for doing the mappings.

    Jackson offers some support for JAXB annotations, but as far as I know is not a JAXB (JSR-222) compliant implementation. It is not guaranteed to interpret JAXB annotations according to the specification.

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

Sidebar

Related Questions

I had asked a question very much similar to this in the thread: https://stackoverflow.com/questions/11259474/store-the-numericals-in-char-array-into-an-integer-variable-in-vc
I have asked a question similar to this in the past but this is
I've already asked similar question on this issue on stack overflow already, but I
I know similar permutations of this question have been asked before, but the answers
This is similar to this question I asked last week. My dataGrid is populated
This question is very similar to an earlier question I asked ( This Question
This is similar to a question that has already been asked. However, I am
I found this on Google, click here , which someone asked a similar question,
Similar questions to this my have been asked a lot of times before. But
This question is very similar to the question asked here so I hope this

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.