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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:48:42+00:00 2026-05-27T13:48:42+00:00

I have a complex object I’m getting back as a return value from the

  • 0

I have a complex object I’m getting back as a return value from the usual “API I have no control over”.

For some API calls the returned XML looks like:

<APICall1>
  <VeryComplexObject>
    <VeryComplexObjectElements... >
  </VeryComplexObject>
</APICall1>

No problem, I just use

@XmlElement
private VeryComplexObject VeryComplexObject;

and it’s business as usual.

But a few calls want to return:

<APICall2>
    <VeryComplexObjectElements... >
</APICall2>

Is there an annotation I can use to suppress the <VeryComplexObject> tags for unmarshal but get the inner element tags?

  • 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-27T13:48:43+00:00Added an answer on May 27, 2026 at 1:48 pm

    You could use JAXB with StAX to accomplish this by leveraging a StreamFilter to ignore an XML element:

    package forum8526002;
    
    import java.io.StringReader;
    
    import javax.xml.bind.*;
    import javax.xml.bind.annotation.*;
    import javax.xml.stream.*;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Foo.class);
    
            XMLInputFactory xif = XMLInputFactory.newFactory();
            StringReader xml = new StringReader("<APICall2><VeryComplexObjectElements><Bar>Hello World</Bar></VeryComplexObjectElements></APICall2>");
            XMLStreamReader xsr = xif.createXMLStreamReader(xml);
            xsr = xif.createFilteredReader(xsr, new Filter());
    
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            Foo foo = (Foo) unmarshaller.unmarshal(xsr);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.marshal(foo, System.out);
        }
    
        @XmlRootElement(name="APICall2")
        static class Foo {
    
            @XmlElement(name="Bar")
            private String bar;
    
        }
    
        static class Filter implements StreamFilter {
    
            @Override
            public boolean accept(XMLStreamReader reader) {
                return !(reader.isStartElement() && reader.getLocalName().equals("VeryComplexObjectElements"));
            }
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex value object class that has 1) a number or read-only
I have a fairly complex object which has some C# code written to render
I'm trying to create a controller for a custom complex object but have some
If I have a complex object, can I inherit from it and remove or
I have some complex object graphs, when I want to send them down to
If i have a complex object, what is the best practice pattern to write
I have a pretty complex object graph G with an object o1 in G
What is the format for databinding to a complex object? I have a linq
I have a List of a complex type - an object with a few
I have a complex network of objects being spawned from a sqlite database using

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.