Skip to main content

1b) Annotation your JAXB beans to enable MTOM

If you're doing code first, you need to add an annotation to your POJO to tell JAXB that the field is a candidate for MTOM optimization. Lets say we have a Picture class with has Title and ImageData fields, then it might look like this:

@XmlType
public class Picture {
   private String title;

   @XmlMimeType("application/octet-stream")
   private DataHandler imageData;

   public String getTitle() { return title; }
   public void setTitle(String title) { this.title = title; }

   public DataHandler getImageData() { return imageData; }
   public void setImageData(DataHandler imageData) 
      { this.imageData = imageData; }
}

Note the use of 'application/octet-stream'. According to the standard, you should be able to use any MIME type you like, in order to specify the actual content of the attachment. However, due to a defect in the JAX-B reference implementation, this won't work.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!