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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:37:20+00:00 2026-06-05T05:37:20+00:00

Is there a way to configure the @XmlTransient JPA2.0 annotation that it will only

  • 0

Is there a way to configure the @XmlTransient JPA2.0 annotation that it will only block the JAXB mechanism when a Java-Object is serialized to xml and not when the incoming XML is transformed to a java object?

Background: I have a REST api which speaks XML. There is an endpoint to create a new Attachment object. As we speak of attachment there is a byte[] field in this class. In further listings of attachments i don’t want to deliver the byte[] content of each attachment.

@Entity
@XmlRootElement
public class Attachment {

private String name;

private String mimeType;

private byte[] dataPart;

public String getName() {
    return name;
}

public void setName( String name ) {
    this.name = name;
}

public String getMimeType() {
    return mimeType;
}

public void setMimeType( String mimeType ) {
    this.mimeType = mimeType;
}

public byte[] getDataPart() {

    return dataPart.clone();
}

public void setDataPart( byte[] dataPart ) {
    this.dataPart = dataPart.clone();
}
}

So, when i mark the getDataPart() with XmlTransient, the data of the incoming byte[] is ignored and set to null -> it’s lost.
Anyone an idea how to specifify the direction of the XmlTransient?

  • 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-05T05:37:22+00:00Added an answer on June 5, 2026 at 5:37 am

    I have to answer the question myself =)
    I solved this by using a custom XmlAdapter that will tranlsate the binary data only in one direction. This is still a hack and we are not using this any more. Reasons below.

    Here is the adapter:

    public class DuplexBase64MarshallAdapter extends XmlAdapter<String, byte[]> {
    
            /**
             * running the adapter in half duplex mode means, the incoming data is marshaled but the
             * outgoing data not.
             */
            public static final boolean HALF_DUPLEX = false;
    
            /**
             * Running the adapter in full duplex means, the incoming and outgoing data is marshalled.
             */
            public static final boolean FULL_DUPLEX = true;
    
            private boolean isFullDuplexMode;
    
            public DuplexBase64MarshallAdapter() {
                this.isFullDuplexMode = HALF_DUPLEX;
            }
    
            /**
             * Constructor
             * 
             * @param fullDuplex
             *            use {@link #HALF_DUPLEX} or {@link #FULL_DUPLEX}
             */
            public DuplexBase64MarshallAdapter( boolean fullDuplex ) {
                this.isFullDuplexMode = fullDuplex;
            }
    
            @Override
            public byte[] unmarshal( String v ) throws Exception {
                return Base64.decode( v );
            }
    
            /**
             * Return always an empty string. We do not want to deliver binary content here.
             */
            @Override
            public String marshal( byte[] v ) throws Exception {
                if( isFullDuplexMode ) {
                    return Base64.encodeBytes( v );
                }
                return "";
            }
    
        }
    

    The entity needs to be annotated with this adapter:

    @Entity
    @XmlRootElement
    public class Attachment {
    
        private String name;
    
        private String mimeType;
    
        private byte[] dataPart;
    
        public String getName() {
            return name;
        }
    
        public void setName( String name ) {
            this.name = name;
        }
    
        public String getMimeType() {
            return mimeType;
        }
    
        public void setMimeType( String mimeType ) {
            this.mimeType = mimeType;
        }
    
        @XmlJavaTypeAdapter( DuplexBase64MarshallAdapter.class )
        public byte[] getDataPart() {
    
            return dataPart.clone();
        }
    
        public void setDataPart( byte[] dataPart ) {
            this.dataPart = dataPart.clone();
        }
    }
    

    This solution works as exepcted. But there is a drawback: One of the intentions was to not let hibernate load the binary data while processing/loading attachment data. But thats not how it works. The binary data is loaded by hibernate in this case because it is send to the XMLAdapter but not translated into base64 🙁

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

Sidebar

Related Questions

Is there a way to configure JAXB to so that a generated class implements
Is there a way to configure hg com so that in the commit message
Is there a way to configure postfix to use a relay only if direct
Is there a way to configure YAP (and/or SWI prolog) so they will preserve
Is there a way to configure Pyramid so that when MongoDB fails over to
Is there a way to configure a mysql table so that writing and reading
Is there a way to configure an application shortcut so that a Windows shell
Is there any way to configure an SVN server such that it does not
Is there a way to configure RubyMine 3.1 to only use two spaces to
is there a way to configure Expires headers for static resources in a Java

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.