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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:18:57+00:00 2026-05-20T15:18:57+00:00

The code attached below produces sporadic test failures (JUnit), works 80% of the time.

  • 0

The code attached below produces sporadic test failures (JUnit), works 80% of the time.
I’m using a static Templates object. In the case of failure a different than expected JAXB object is placed into ‘result’ from the transformer.transform(jaxbSource, result) method call.

I’ve tried locks and synchronizes sections in vain. Also the Templates object is supposed to be thread safe according to spec. Something weird is happening in the transform.

Error symptom: JUnit test failure – suddenly the wrong object is returned from the transform.

Any ideas?

private <S, T> S transform(final Templates template, final Class resultClass, final T data) throws JAXBException, TransformerException {
    Transformer transformer = template.newTransformer();
    final JAXBSource jaxbSource = new JAXBSource(getCachedJAXBContext(data.getClass()), data);
    final Result result = new JAXBResult(getCachedJAXBContext(resultClass));
    transformer.transform(jaxbSource, result);
    return (S) ((JAXBResult) result).getResult();
}
  • 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-20T15:18:57+00:00Added an answer on May 20, 2026 at 3:18 pm

    Since you have multiple classes mapped to the same root element name, you need to pass the type you wish to unmarshal as a parameter to the unmarshal operation. This will mean transforming to an intermediate representation such as: DOM, byte[], String, etc:

    private <S, T> S transform(final Templates template, final Class resultClass, final T data) throws JAXBException, TransformerException {
        Transformer transformer = template.newTransformer();
        final JAXBSource jaxbSource = new JAXBSource(getCachedJAXBContext(data.getClass()), data);
        final Result result = new DOMResult();
        transformer.transform(jaxbSource, result);
        return (S) getCachedJAXBContext(resultClass).createUnmarshaller().unmarshal(new DOMSource(result.getNode()), resultClass).getValue();
    }
    

    For more information:

    • http://bdoughan.blogspot.com/2011/03/handling-duplicate-xmlrootelement.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code attached to a button, to attempt to open a
I'm using a tutorial plugin - http://particlebits.com/code/jquery-tutorial/ which has this code attached to the
For the attached code, I get the following compile time error : exception during
I will keep this quick. The attached code for the most part works i
The javascript code is attached below. Two push pins are added to a Bing
The attached below C code when run gives the error summary: malloc.c:3074: sYSMALLOc: Assertion
In my code attached below, I'm trying to upload a file via ASP.NET. I
Hey guys, attached below is my code, and then my CSS. They item fades
I have this (attached)code which works perfectly on all the AVDs I create with
I am assigning new arrows to my jscrollpane with the below code. This works

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.