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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:06:09+00:00 2026-06-02T13:06:09+00:00

I’m new to java XML binding. This is my class import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement;

  • 0

I’m new to java XML binding.

This is my class

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * @author Martin Burchard
 * 
 */
@XmlRootElement(name = "user")
    public class User {
    private String id;
    private String nickname;
    private String email;
    private String password;

    @XmlElement(name = "id")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @XmlElement(name = "nickname")
    public String getNickName() {
        return nickname;
    }

    public void setNickName(String nickname) {
        this.nickname = nickname;
    }

    @XmlElement(name = "email")
    public String getEMail() {
        return email;
    }

    public void setEMail(String email) {
        this.email = email;
    }

    @XmlElement(name = "password")
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

}

During creation/registration of a user the password must be given, but later, when asking for userinformation, the XML should not contain the password element.
Is it possible to define an Element as writeonly?

  • 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-06-02T13:06:10+00:00Added an answer on June 2, 2026 at 1:06 pm

    Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.

    MOXy has an @XmlReadOnly extension. The field/property annotated with @XmlReadOnly will be populated during an unmarshal (read), but will not be written during a marshal.

    User

    package forum10208143;
    
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import org.eclipse.persistence.oxm.annotations.XmlReadOnly;
    
    /**
     * @author Martin Burchard
     * 
     */
    @XmlRootElement(name = "user")
    public class User {
        private String id;
        private String nickname;
        private String email;
        private String password;
    
        @XmlElement(name = "id")
        public String getId() {
            return id;
        }
    
        public void setId(String id) {
            this.id = id;
        }
    
        @XmlElement(name = "nickname")
        public String getNickName() {
            return nickname;
        }
    
        public void setNickName(String nickname) {
            this.nickname = nickname;
        }
    
        @XmlElement(name = "email")
        public String getEMail() {
            return email;
        }
    
        public void setEMail(String email) {
            this.email = email;
        }
    
        @XmlElement(name = "password")
        @XmlReadOnly
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
    }
    

    jaxb.properites

    To specify MOXy as your JAXB provider you need to add a file called jaxb.properties in the same package as your domain model with the following entry:

    javax.xml.bind.context.factory = org.eclipse.persistence.jaxb.JAXBContextFactory
    

    Demo

    package forum10208143;
    
    import java.io.File;
    import javax.xml.bind.*;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(User.class);
    
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            File xml = new File("src/forum10208143/input.xml");
            User user = (User) unmarshaller.unmarshal(xml);
    
            System.out.println(user.getPassword());
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(user, System.out);
        }
    
    }
    

    input.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <user>
        <id>jdoe</id>
        <nickname>Jane</nickname>
        <email>jane.doe@example.com</email>
        <password>secret</password>
    </user>
    

    Output

    secret
    <?xml version="1.0" encoding="UTF-8"?>
    <user>
       <email>jane.doe@example.com</email>
       <id>jdoe</id>
       <nickname>Jane</nickname>
    </user>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters

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.