users@jaxb.java.net

Re: unmarshalling not woriking correctly? What did I do?

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Fri, 17 Nov 2006 08:32:06 -0800

See https://jaxb.dev.java.net/guide/Unmarshalling_is_not_working__Help_.html

Frank wrote:
> I'm haing a problem of somethign not unmarshaling corrdctly. I have a
> string that contains the folowing (pretty printed here):
> <?xml version="1.0" encoding="UTF-8"?>
> <ns1:advertiseSS advertisementID="1b094a9d-063b-409b-8a3b-923061a5c983"
> commandDateTime="2006-05-25T09:49:56.593-04:00" userID="peer"
> xmlns="http://mitre.org/DDS" xmlns:ns1="http://mitre.org/DDS">
>
> <ns1:returnAddress>http://128.96.185.16:8080/DDS/services/DDS</ns1:returnAddress>
>
> <ns1:sourceAddress>http://128.96.185.16:8080/DDS/services/DDS</ns1:sourceAddress>
> <ns1:metadata>
> <ns1:title ns2:classification="U" ns2:ownerProducer="USA"
> xmlns:ns1="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
> xmlns:ns2="urn:us:gov:ic:ism:v2">MCS_DEMO</ns1:title>
> <ns3:description ns4:classification="U" ns4:ownerProducer="USA"
> xmlns:ns3="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
> xmlns:ns4="urn:us:gov:ic:ism:v2">MCS_Desc</ns3:description>
> <ns5:creator ns6:classification="U" ns6:ownerProducer="USA"
> xmlns:ns5="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
> xmlns:ns6="urn:us:gov:ic:ism:v2">
> <ns5:Organization>
> <ns5:name>MCS</ns5:name>
> </ns5:Organization>
> </ns5:creator>
> <ns7:subjectCoverage
> xmlns:ns7="http://metadata.dod.mil/mdr/ns/DDMS/1.2/">
> <ns7:Subject>
> <ns7:category ns7:label="Ground"/>
> <ns7:keyword ns7:value="MCSAdv1"/>
> </ns7:Subject>
> </ns7:subjectCoverage>
> <ns8:temporalCoverage xmlns:ns8="http://mitre.org/DDS/metadata">
> <ns8:start>2006-05-25T09:38:10-04:00</ns8:start>
> <ns8:end>2006-05-25T14:38:10-04:00</ns8:end>
> </ns8:temporalCoverage>
> <ns9:geospatialCoverage xmlns:ns9="http://mitre.org/DDS/metadata">
> <ns9:lowerCorner>-170.0 46.0</ns9:lowerCorner>
> <ns9:upperCorner>-169.0 47.0</ns9:upperCorner>
> </ns9:geospatialCoverage>
> <ns10:security ns11:classification="U" ns11:ownerProducer="USA"
> xmlns:ns10="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
> xmlns:ns11="urn:us:gov:ic:ism:v2"/>
> <ns12:identifier ns12:qualifier="Test" ns12:value="value"
> xmlns:ns12="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"/>
> </ns1:metadata>
> <ns1:hopCount>1</ns1:hopCount>
> </ns1:advertiseSS>
>
>
>
> But when I run this code:
> code segment from one funtion
> JAXBContext jc = JAXBContext.newInstance(
> "msg.pkg");
> Unmarshaller u = jc.createUnmarshaller();
> Object dds = (Object) u.unmarshal(new ByteArrayInputStream(
> ddsMsg.getBytes()));
> JAXBContext jc =
> JAXBContext.newInstance("csds.message:org.mitre.dds.jaxb");
> StringWriter result = new StringWriter();
> Marshaller m = jc.createMarshaller();;
>
> code segment from another
> JAXBContext jc =
> JAXBContext.newInstance("csds.message:org.mitre.dds.jaxb");
> StringWriter result = new StringWriter();
> Marshaller m = jc.createMarshaller();;
> m.marshal(msgObj, result);
> msgStr = result.toString();
>
> msgStr has value (pretty printed):
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <ns6:advertiseSS advertisementID="1b094a9d-063b-409b-8a3b-923061a5c983"
> userID="peer" commandDateTime="2006-05-25T09:49:56.593-04:00"
> xmlns:ns4="http://metadata.dod.mil/mdr/ns/DDMS/1.2/"
> xmlns:ns3="urn:us:gov:ic:ism:v2"
> xmlns:ns5="http://mitre.org/DDS/metadata"
> xmlns:ns2="urn:us:gov:dod:army:cerdec:jbfsa:csds:r1"
> xmlns:ns6="http://mitre.org/DDS">
> <hopCount>0</hopCount>
> </ns6:advertiseSS>
>
> It's like it did not use the value in the beginning. Also some of the
> required elements are missing so would not even pass schema check.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com