Skip to main content

Schemagen.exe creates reversed schema-content

2 replies [Last post]
aronolsen
Offline
Joined: 2008-10-31
Points: 0

After having created a small set of JAXB-annotated classes I am perfectly able to have my classes marshalled and unmarshalle to and from XML using JAXB.
As I want to have schema-validation applied when doing unmarshalling I created an XML-schema for the classes using the schemagen.exe executable in the JDK 1.6.0_10 distribution.
In the resulting XML-schema all XML-sequences contains data in the exact opposite ordering, compared to how JAXB is marshalling the content. Thus, I cannot use the produced schema for validation, unless I manually reverse the content of every XML-sequence found in it. I have a hard time believing that this is a true bug, but I am also completely blank on what to do with the problem.
Can anybody verify this as a bug?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
aronolsen
Offline
Joined: 2008-10-31
Points: 0

Here is a small Java-program for reproducing this bug:

JaxbTest.java:
//----------------------------------------------------
package com.carlbro.fotsfs.pub;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.carlbro.fotsfs.server.ServiceProperties;

@XmlRootElement
public class JaxbTest
{
@XmlElement
String property1;
@XmlElement
String property2;
@XmlElement
String property3;

public String toString()
{
return "JaxbTest( '" + property1 + "','" + property2 + "','" + property3 + "' )";
}
static public void main( String argv[] )
{
Class contextClasses[] = { JaxbTest.class };

try
{
JaxbTest data = new JaxbTest();
data.property1 = "prop1";
data.property2 = "prop2";
data.property3 = "prop3";

JAXBContext jaxbContext = JAXBContext.newInstance( contextClasses );

Marshaller m = jaxbContext.createMarshaller();
m.setProperty( "jaxb.formatted.output", true );
ByteArrayOutputStream bos = new ByteArrayOutputStream();

System.out.println("Marshalling " + data + " ...");
m.marshal( data, bos );
String result = bos.toString();
System.out.println("Marshalled result:\n" + result );

ByteArrayInputStream is = new ByteArrayInputStream( result.getBytes() );

Unmarshaller um = jaxbContext.createUnmarshaller();
System.out.println("Unmarshalling...");
data = (JaxbTest)um.unmarshal( is );
System.out.println("Unmarshalled result:\n" + data );
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
//----------------------------------------------------

Here is the .bat file for creating the XML-schema:
rem ---------------------------------------------------------------
set schemadir=.\java\com\carlbro\fotsfs\pub
set classes=
set classes=%classes% com.carlbro.fotsfs.pub.JaxbTest

C:\Java\jdk1.6.0_10\bin\schemagen -d %schemadir% -cp .\bin %classes%
rem ---------------------------------------------------------------

Here is output from the program:
----------------------------------------------
Marshalling JaxbTest( 'prop1','prop2','prop3' ) ...
Marshalled result:

prop1 prop2 prop3

Unmarshalling...
Unmarshalled result:
JaxbTest( 'prop1','prop2','prop3' )
----------------------------------------------

Here is the generated XML-schema content:
-----------------------------------------------------------









-----------------------------------------------------------

As can be seen, the ordering of elements in the sequence is reversed as compared to the JAXB marshal-output and/or member-ordering in JaxbTest.java.

/Aron

aronolsen
Offline
Joined: 2008-10-31
Points: 0

Sorry, missed the "proporder" attribute, but anyways:
It must be a design-issue, forcing us lazies to specify our ordering explicitly.
Thanks for paying notice.