Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Jaxb not validating values returned from unmarshal method in DateTimeAdapter #1199

Open
puser-680 opened this issue May 28, 2018 · 0 comments

Comments

@puser-680
Copy link

We have created a Datetime adapter to handle empty DateTime tag ( which we are in need to nullify a column in the db) but the below code doesn't work when enable schema validation.
Since seems that the schema validation validate the received value from the xml request message and not from the unmarshal value.

`
public class DateTimeAdapter extends XmlAdapter<String, Date>{

private String pattern = "yyyy-MM-dd'T'HH:mm:ss";

/* (non-Javadoc)
 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
 */
public String marshal(Date date) throws Exception {
	if(date == null)
		return null;
	return new SimpleDateFormat(pattern).format(date);
}

public Date unmarshal(String dateString) throws Exception
{
	if(!dateString.isEmpty())
		return new SimpleDateFormat(pattern).parse(dateString);
	return new SimpleDateFormat(pattern).parse("1900-01-01T00:00:00");
}

}
`

Xml Message Instance

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tes="testtnsJ"> <soapenv:Header/> <soapenv:Body> <tes:createTest> <!--Optional:--> <request> <!--Optional:--> <requesterContext> <userId>qwd</userId> <testDate></testDate> </requesterContext> </request> </tes:createTest> </soapenv:Body> </soapenv:Envelope>

Enable schema validation
<jaxws:properties> <entry key="schema-validation-enabled" value="true" /> </jaxws:properties>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant