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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:56:59+00:00 2026-05-30T23:56:59+00:00

In jaxb, how do you convert a string in xsd to java.util.UUID? Is there

  • 0

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?

  • 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-30T23:57:01+00:00Added an answer on May 30, 2026 at 11:57 pm

    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)

    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               targetNamespace="http://www.example.com"
               xmlns="http://www.example.com"
               elementFormDefault="qualified">
        <xs:simpleType name="uuid-type">
            <xs:restriction base="xs:string">
                <xs:pattern value=".*"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:complexType name="example-type">
            <xs:all>
                <xs:element name="uuid" type="uuid-type"/>
            </xs:all>
        </xs:complexType>
        <xs:element name="example" type="example-type"/>
    </xs:schema>
    

    Bindings: (bindings.xjb) (Note that for brevity in printMethod and parseMethod I assumed that the UuidConverter class was in the default package. These should be fully qualified in reality. So if UuidConverter where in package com.foo.bar then the values should be like com.foo.bar.UuidConverter.parse and com.foo.bar.UuidConverter.print

    <!-- Modify the schema location to be a path or url -->
    <jxb:bindings version="1.0"
                  xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  node="/xs:schema"
                  schemaLocation="example.xsd">
        <!-- Modify this XPATH to suit your needs! -->
        <jxb:bindings node="//xs:simpleType[@name='uuid-type']">
            <jxb:javaType name=" java.util.UUID"
                          parseMethod="UuidConverter.parse"
                          printMethod="UuidConverter.print"/>
        </jxb:bindings>
    </jxb:bindings> 
    

    UuidConverter.java:

    import java.util.UUID;
    
    public class UuidConverter {
        public static UUID parse(String xmlValue) {
            return UUID.fromString(xmlValue);
        }
    
        public static String print(UUID value) {
            return value.toString();
        }
    }
    

    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. :-/

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

Sidebar

Related Questions

I've used JAXB Marshaller as well as my own marshaller for marshalling pure java
Is there an equivalent library for JAXB in .NET? I am trying to convert
Given a scenario: I have my own system's object structure. Now there are more
We have a medium sized Java server that has data flowing in the following
Need: take in XML and save data to database. Currently using: JAXB to convert
I have some jaxb objects (instantiated from code generated from xsd by jaxb) that
JAXB generated from XSD base64Binary and hexBinary to byte array. I have xsd element
I am using JAXB to serialize data to XML from java objects. I do
At http://jaxb.java.net/ it says JAXB its under dual license consisting of the CDDL v1.0
We have this JAXB annotation: @XmlElement(name = Strategy, required = true) protected List<Strategy> strategy;

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.