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

  • Home
  • SEARCH
  • 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 9123221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:17:12+00:00 2026-06-17T06:17:12+00:00

I am using @XmlTransient for hiding some Strings in output XML file. It works

  • 0

I am using @XmlTransient for hiding some Strings in output XML file. It works fine while marshalling and the XML is fine.
However when I unmarshall the XML, the @XmlTransient marked values appear as null.

  • 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-17T06:17:13+00:00Added an answer on June 17, 2026 at 6:17 am

    What @XmlTransient Does

    @XmlTransient marks the property as unmapped so it is excluded from both marshalling and unmarshalling.

    • http://blog.bdoughan.com/2012/04/jaxb-and-unmapped-properties.html

    What You Could Do

    If you just want to exclude the value from marshalling you may consider using an XmlAdapter

    XmlAdapter (StringAdapter)

    The XmlAdapter will always return "" for the marshal operation and the JAXB implementation will return an empty element. If you are using EclipseLink MOXy as your JAXB implementation you could return null to eliminate the node completely (see: http://blog.bdoughan.com/2012/04/binding-to-json-xml-handling-null.html).

    import javax.xml.bind.annotation.adapters.XmlAdapter;
    
    public class StringAdapter extends XmlAdapter<String, String> {
    
        @Override
        public String marshal(String string) throws Exception {
            return null;
        }
    
        @Override
        public String unmarshal(String string) throws Exception {
            return string;
        }
    
    }
    

    Person

    import javax.xml.bind.annotation.*;
    import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
    
    @XmlRootElement(name="Person")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Person {
    
        String name;
    
        String address;
    
        @XmlJavaTypeAdapter(StringAdapter.class)
        String password;
    
    }
    

    input.xml

    <Person>
        <name> some name </name>
        <password> some password </password>
        <address> some address </address>
    </Person>
    

    Demo

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

    Output

     some password 
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Person>
        <name> some name </name>
        <address> some address </address>
        <password></password>
    </Person>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
Using ASIHTTPRequest, I downloaded a zip file containing a folder with several audio files.
using xmltextreader, how would I load a hashtable. XML: <base><user name=john>2342343</user><user name=mark>239099393</user></base> This was
Using Visual Studio / C#, I've been debugging some nunit tests recently, and am
Using Joomla! 3.0 (Or 2.5, whatever works best), I'm needing to create a system
I'm working on to convert Hibernate objects to XML using JAXB. In our classes,
Using the Exiv2 library to write some exif tags to an image i'm running
I'm using JAXB+Jettison to serve multiformat RESTful (schema-less) service. @XmlTransient annotation served good for
Using a form I am adding some basic fields to my table. I also
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain

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.