java - Marshaling object with StringBuffer attributes -


when marshaling object via jaxb stringbuffer attribute, attribute becomes blank. wrote small program demonstrate problem:

import javax.xml.bind.jaxbcontext; import javax.xml.bind.marshaller; import javax.xml.bind.annotation.xmlelement; import javax.xml.bind.annotation.xmlrootelement;  @xmlrootelement public class jaxbtest {      private string valueone;     private stringbuffer valuetwo;      public static void main(string[] args) throws exception {          jaxbtest object = new jaxbtest();         object.setvalueone("12345");         object.setvaluetwo(new stringbuffer("54321"));          jaxbcontext context = jaxbcontext.newinstance(jaxbtest.class);         marshaller marshaller = context.createmarshaller();         marshaller.marshal(object, system.out);     }      @xmlelement     public string getvalueone() {         return valueone;     }      public void setvalueone(string valueone) {         this.valueone = valueone;     }      @xmlelement     public stringbuffer getvaluetwo() {         return valuetwo;     }      public void setvaluetwo(stringbuffer valuetwo) {         this.valuetwo = valuetwo;     } } 

the output follows:

<?xml version="1.0" encoding="utf-8" standalone="yes"?><jaxbtest><valueone>12345</valueone><valuetwo/></jaxbtest> 

does know why "valuetwo" not being marshaled correctly? btw, using java 1.6.0_22.

thanks in advance!!!

i recommend using jaxb's xmladapter use case:


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -