JaxB marshalling

May 22, 2013 at 7:01 PM
I try to use JaxB HealthVault SDK to upload CCD, code sample:
ObjectFactory factory = new ObjectFactory();
DataXml dataXml = factory.createDataXml();

Thing thing = new Thing();
thing.setTypeId(thingType);
thing.setThingState(ThingState.ACTIVE);
thing.setData(jaxBElement);
but get an error back:
unable to marshal type "com.microsoft.hsg.thing.oxm.jaxb.thing.DataXml" as an element because it is missing an @XmlRootElement annotation
I tried to use JAXBElement as wrapper, but then I got this error:
"javax.xml.bind" doesnt contain ObjectFactory.class or jaxb.index
What am I doing wrong?
Coordinator
Jun 11, 2013 at 10:18 PM
Hi Alex,

Try looking at the Jaxb unit tests for how it works. You'll end up with code like this:
public void CreateThing() {
        Thing thing = new Thing();
        thing.setData(createValidAllergy());
        
        PutThingsRequest request = new PutThingsRequest();
        request.getThing().add(thing);
        
        PutThingsResponse response = (PutThingsResponse)requestTemplate.makeRequest(request);
}
        
private Allergy createValidAllergy() {
        Allergy allergy = new Allergy();
        allergy.setName(new CodableValue("Dairy", 
                new CodedValue("value", "family", "type", "version")));
        
        ApproxDate dt = new ApproxDate();
        dt.setY(1960);
        StructuredApproxDate sad = new StructuredApproxDate();
        sad.setDate(dt);
        ApproxDateTime firstObs = new ApproxDateTime();
        firstObs.setStructured(sad);
        allergy.setFirstObserved(firstObs);
        
        allergy.setAllergenCode(new CodableValue("my-code"));
        
        Name name = new Name();
        name.setFull("Dr. Who");
        Person person = new Person();
        person.setName(name);
        allergy.setTreatmentProvider(person);
        
        return allergy;
    }