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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:29:27+00:00 2026-05-16T15:29:27+00:00

Currently, JAXB is creating a point class from the xml schema I have specified.

  • 0

Currently, JAXB is creating a point class from the xml schema I have specified. However, I would prefer it to use the existing java.awt.Point class. And for any other types I have defined to use and import java.awt.Point too.

Here is my point code:

<xs:complexType name="point">
  <xs:sequence>
    <xs:element name="x" type="xs:int" />
    <xs:element name="y" type="xs:int" />
  </xs:sequence>
</xs:complexType>

Is this possible?

  • 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-16T15:29:28+00:00Added an answer on May 16, 2026 at 3:29 pm

    I don’t know if my solution is very elegant but I believe it works as you demand.

    Consider class Test with a property p of type java.awt.Point:

    @XmlRootElement
    public class Test {
        @XmlElement
        @XmlJavaTypeAdapter(PointAdapter.class)
        public Point p;
    }
    

    The class PointAdapter is as follows:

    class PointAdapter extends XmlAdapter<String, Point> {
    
        @Override
        public String marshal(Point v) throws Exception {
            return String.format("%d;%d", v.x, v.y);
        }
    
        @Override
        public Point unmarshal(String v) throws Exception {
            String[] coords = v.split(";");
            return new Point(Integer.parseInt(coords[0]), Integer.parseInt(coords[1]));
        }
    
    }
    

    If you don’t create your Java classes by hand but let them generate by xjc there is a possibility to specify the XmlAdapter in the schema too; either through a seperate binding file that you can specify with the -b option of xjc or embedded in your XSD. Personally I prefer the first solution as this keeps the schema clean. Since it has been a while since I played with this I refer you to the JAXB documentation (look for MyDatatypeConverter; this should be the most relevant part).

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

Sidebar

Related Questions

Is it possible to use JAXB to unmarshall xml to a specific Java class
I have a service that needs to generate xml. Currently I am using jaxb
I'm trying to use JAXB to pull some elements from a large XML file
How do I get the jaxb:class element to show? I currently have the following
Currently I'm busy on a project using XML messaging. I have one general schema,
I'm currently attempting to unmarshal some existing XML into a few classes I have
As far as I know, there is currently no JAXB implementation which would work
I need to generate a big xml. I am currently using JAXB 2.0 .
i have this xpath defined for moxy in a jaxb class @XmlPath(child::*/REG) public List
I am currently trying to use the XMLUnit library to compare two XML files.

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.