XMLインスタンスをPOJOにアンマーシャリングするために、JAXB 2.0JDK6を使用しています。
カスタム検証を追加するために、プロパティのセッターに検証呼び出しを挿入しましたが、プライベートであるにもかかわらず、アンマーシャラーはセッターを呼び出さず、プライベートフィールドを直接変更しているようです。
マーシャル解除の呼び出しごとに、この特定のフィールドに対してカスタム検証が行われることが重要です。
私は何をすべきか?
コード:
@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;
}
}