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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:30:04+00:00 2026-05-14T07:30:04+00:00

I am using JAXB 2.0 JDK 6 in order to unmarshall an XML instance

  • 0

I am using JAXB 2.0 JDK 6 in order to unmarshall an XML instance into POJOs.

In order to add some custom validation I have inserted a validation call into the setter of a property, yet despite it being private, it seems that the unmarshaller does not call the setter but directly modifies the private field.

It is crucial to me that the custom validation occurs for this specific field every unmarshall call.

What should I do?

Code:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "LegalParams", propOrder = {
    "value"
})
public class LegalParams {

    private static final Logger LOG = Logger.getLogger(LegalParams.class);

    @XmlTransient
    private LegalParamsValidator legalParamValidator;

    public LegalParams() {

        try {
            WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
            LegalParamsFactory legalParamsFactory = (LegalParamsFactory) webApplicationContext.getBean("legalParamsFactory");
            HttpSession httpSession = SessionHolder.getInstance().get();
            legalParamValidator = legalParamsFactory.newLegalParamsValidator(httpSession);
        }
        catch (LegalParamsException lpe) {
            LOG.warn("Validator related error occurred while attempting to construct a new instance of LegalParams");
            throw new IllegalStateException("LegalParams creation failure", lpe);
        }
        catch (Exception e) {
            LOG.warn("Spring related error occurred while attempting to construct a new instance of LegalParams");
            throw new IllegalStateException("LegalParams creation failure", e);
        }
    }

    @XmlValue
    private String value;

    /**
     * Gets the value of the value property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *
     */
    public String getValue() {
        return value;
    }

    /**
     * Sets the value of the value property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     * @throws TestCaseValidationException
     *
     */
    public void setValue(String value) throws TestCaseValidationException {
        legalParamValidator.assertValid(value);
        this.value = value;
    }
}
  • 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-14T07:30:04+00:00Added an answer on May 14, 2026 at 7:30 am

    JAXB uses field access because you configured it to use field access by annotating a field with @XmlValue and by declaring @XmlAccessorType(XmlAccessType.FIELD).

    To use property access, you can move @XmlValue to either getter or setter (@XmlAccessorType is not needed at all).

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

Sidebar

Related Questions

I am doing this using JAXB to unmarshall some XML into Java objects: My
I have some problem when unmarshaling a .xml at a web service using JAXB.
I have always been using jaxb for parsing XML files into java object. This
I am using JAXB to unmarshal an XML file into an object tree. The
I'm using JAXB for quick-and-dirty XML generation. I have a class that represents a
We're using JAXB to unmarshall a fragment of XML which looks a bit like
I have this schema and i'm using JAXB to generate java stub files. <?xml
I have an application doing XML<->conversions using Jaxb and automatically generated classes with maven-jaxb2-plugin.
I have a fairly large repetitive XML to create using JAXB. Storing the whole
We are using JAXB to handle our wsdl validation. In the wsdl we have

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.