In jaxb, how do you convert a string in xsd to java.util.UUID? Is there a built-in data type converter or do I have to create my own custom converter?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
This is much easier to do if you start with Java classes and use JAXB annotations. However, to do this using schema you must use a custom bindings file. Here is an example:
Schema: (example.xsd)
Bindings: (bindings.xjb) (Note that for brevity in
printMethodandparseMethodI assumed that theUuidConverterclass was in the default package. These should be fully qualified in reality. So ifUuidConverterwhere in packagecom.foo.barthen the values should be likecom.foo.bar.UuidConverter.parseandcom.foo.bar.UuidConverter.printUuidConverter.java:
Sadly I can’t point you to a good reference because its really not documented well. There are bits and pieces of how it all works spread out in blog posts. Took me a few hours to make this work the first time. :-/