users@jaxb.java.net

Re: [jaxb-1.x] Marshalling just a type without nested elements produces empty string

From: Dmitri Colebatch <dim_at_colebatch.com>
Date: Sat, 1 Jul 2006 16:44:54 +1000

Hi Kostis,

You're asking two questions here. The first one relates to what code
xjc generates for you, and the second relates to how jaxb2 handles
classes that don't have @XmlRootElement annotations.

The answer to the first is that xjc will generate classes with
@XmlRootElement for any global elements defined in your schema.

The answer to the second is (I think) that if you try to marshall an
object of class Foo where Foo doesn't have a @XmlRootElement
annotation jaxb2 won't marshall the class.

does that help?

cheers
dim

On 7/1/06, Kostis Anagnostopoulos <ankostis_at_gmail.com> wrote:
> Hi to all,
>
> When i try to marshal a schema type-derived java object containing
> only attributes then i get an empty string, although its attributes
> have values.
>
> See for instance the "executionInfoType" at the end of the mail.
>
> When i modified my schema, and added on nested element, and
> additionally set it indeed to something, then i got all content
> (attributes plus nested element).
>
> Alternatively, i worked around that problem by adding one top-level
> element of "executionInfo" type, and used that element for marshaling.
>
> I don't know whether this is considered "normal" (I've found some
> similar old threads), but either way i believe that 2 actions has to
> be taken:
> 1. a notification should be included into the "Limitations" section
> of the Release Notes,
> 2. the marshaller should throw an Exception when marshaling types
> into empty strings.
>
> Should i file an issue ?
>
>
> Below is the schema i use:
> ----------------------------------------------------------------------------------------
>
> <xsd:schema
> <xsd:complexType name="executionInfoType">
> <xsd:attribute name="transformerProgramVersion" type="xsd:string"
> use="required" />
> <xsd:attribute name="transformationDate" type="xsd:dateTime"
> use="optional" />
> <xsd:attribute name="configFile" type="xsd:string" use="required" />
> <xsd:attribute name="configFileVersion" type="xsd:string"
> use="required" />
> </xsd:complexType>
> </xsd:schema>
> ----------------------------------------------------------------------------------------
>
>
> Greetings
> ankostis
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>