Skip to main content

A List of int[]

2 replies [Last post]
akaranta
Offline
Joined: 2006-09-11
Points: 0

I am generating a schema on annotated Java classes. I want to have a List map to xml something like

this:

1 2 4 12
2 1 3

What I now have is

private List _groupHeaderColSpans ;
@XmlElementWrapper( name = "group-header-col-spans" )
@XmlElement( name = "spans" )
public List getGroupHeaderColSpans() { return _groupHeaderColSpans ; }
public void setGroupHeaderColSpans( List spans ) { _groupHeaderColSpans = spans ; }

First of all, I end up w/ 2 schema files being generated instead of one, and when I try to run:
Caught: org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'ns1:intArray' to a(n) 'type definition' component.

I also tried wrapping the int[] in a class and using @XmlList, but then I end up with xml like this (and

still two schema files):

1
3
6

which is not very nice either.

The Java code for this option:

private List _groupHeaderColSpans ;
@XmlElementWrapper( name = "group-header-col-spans" )
@XmlElement( name = "spans" )
public List getGroupHeaderColSpans() { return _groupHeaderColSpans ; }
public void setGroupHeaderColSpans( List spans ) { _groupHeaderColSpans = spans ; }
// ...
@XmlType( name = "colSpanType" )
public static class ColSpans {
private int[] _colspans ;

public ColSpans() {}
public ColSpans( int... spans ) { _colspans = spans ; }

@XmlList
// @XmlValue // this does not seem to make any difference (which is documented in @XmlList javadoc)
public int[] getColSpans() { return _colspans ; }
public void setColSpans( int[] colspans ) { _colspans = colspans ; }

}

For a single int[] @XmlList works fine, but I can't figure out how to do the same thing on a List

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
akaranta
Offline
Joined: 2006-09-11
Points: 0

Actually the latter (using a class to wrap the array) works. The test code inserted Lists of wrong types of objects and that made jaxb produce weird xml. It seems jaxb (2.1.2) is not performing any type checking on the type of stuff contained in the lists and just acts weird (instead of failing and throwing an exception) if the wrong type of data is encountered.

Problem solved, anyhow.

kohsuke
Offline
Joined: 2003-06-09
Points: 0

I'm curious what you mean by "act weird". If there's anything we can do better in the JAXB RI about handling an error, let us know...