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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:04:15+00:00 2026-06-06T06:04:15+00:00

I am using JAXB XMLadapter to marshal and unmarshal Boolean values. The application’s XML

  • 0

I am using JAXB XMLadapter to marshal and unmarshal Boolean values. The application’s XML file will be accessed by C# application also. We have to validate this XML file and this is done using XSD. C# application writes “True” value for Boolean nodes. But the same does get validated by our XSD as it only allows “true/false” or “1/0”. So we have kept String for boolean values in XSD and that string will be validated by XMLAdapter to marshal and unmarshal on our side.
The XML Adapter is as follows:

public class BooleanAdapter extends XmlAdapter<String, Boolean> {

    @Override
    public Boolean unmarshal(String v) throws Exception {

        if(v.equalsIgnoreCase("true") || v.equals("1")) {
            return true;
        } else if(v.equalsIgnoreCase("false") || v.equals("0")) {
            return false;
        } else {
            throw new Exception("Boolean Value from XML File is Wrong.");
        }
    }

    @Override
    public String marshal(Boolean v) throws Exception {
        return v.toString();        
    }
}

The code above works in normal conditions, but when invalid data(eg: “abcd” or “”) is read from xml file then the “throw new Exception();” is not getting propagated and the Unmarshal process moves on to read next node.
I want the application to stop as soon as an exception is thrown.
It seems my Exception is getting eaten away.
Any help is much appreciated.

How to resolve this problem?

  • 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-06T06:04:17+00:00Added an answer on June 6, 2026 at 6:04 am

    From the JavaDoc of XMLAdapter#unmarshal(ValueType):

    Throws:
    java.lang.Exception – if there’s an error during the conversion. The caller is responsible for reporting the error to the user through ValidationEventHandler.

    So, yes – the exception is eaten and then reported using ValidationEventHandler, not thrown to the top of your stack.

    Check if you are already using any (custom, perhaps) ValidationEventHandler that groups your exceptions, or use DefaultValidationEventHandler, like this:

    unmarshaller.setEventHandler(new DefaultValidationEventHandler());
    

    It will cause unmarshalling failure on first error.

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

Sidebar

Related Questions

I am using JAXB to unmarshal an XML file into an object tree. The
I have an application doing XML<->conversions using Jaxb and automatically generated classes with maven-jaxb2-plugin.
I have a XML format that I want to marshal using JAXB and it
I'm reading an xml file using Jaxb, now the contents of the xml file
I have some problem when unmarshaling a .xml at a web service using JAXB.
I have a Maven 2 RESTful application using Jersey/JAXB. I generate the JAXB beans
I'm using CXF 2.4 with JAXB. Could I have a global XmlAdapter for all
I'm using JAXB for quick-and-dirty XML generation. I have a class that represents a
I have this schema and i'm using JAXB to generate java stub files. <?xml
I have a fairly large repetitive XML to create using JAXB. Storing the whole

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.