JAXB - manuell Klassen aus xsd

baxbear

Mitglied
Hi,

ich hab versucht manuell Klassen aus einer .xsd zu erstellen weil mein xjc tool nicht funktioniert hab schon alles versucht selbst neu installation es hängt sich immer auf.

Aber egal ich brauche in diesem Fall eh nur eine .xsd umsetzten von daher hier mal was ich gemacht habe und die Fehlermeldung:

[XML]
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="map">
<xs:complexType>
<xs:sequence>
<xs:element name="country" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="x" type="xs:integer" />
<xs:element name="y" type="xs:integer" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
[/XML]

bsp.:
[XML]
<?xml version="1.0" encoding="UTF-8"?>

<map name="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="field.xsd">
<country>
<name>test1</name>
<x>110</x>
<y>20</y>
</country>
<country>
<name>test2</name>
<x>200</x>
<y>30</y>
</country>
</map>
[/XML]

Dazu habe ich folgende Klassen erstellt:

Java:
package game.view.gui;

import javax.xml.bind.annotation.XmlRegistry;

@XmlRegistry
public class ObjectFactory {

	public ObjectFactory() {
	}

	public Map createMap() {
		return new Map();
	}
}

Java:
package game.view.gui;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement( name = "map" )
public class Map {
	@XmlAttribute
	private String name;
	private List<Country> countries = new ArrayList<Country>();
	
	@XmlElement(name = "country")
	public List<Country> getCountries() {
		return countries;
	}
	
	public void setCountries( List<Country> countries ) {
		this.countries = countries;
	}
}

Java:
package game.view.gui;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "country")
public class Country {
	@XmlElement(required = true)
	private String name;
	@XmlElement(required = true)
	private int x;
	@XmlElement(required = true)
	private int y;

	public String getName() {
		return name;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}
}

Die Fehlermeldung lautet wie folgt:

javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "countries"
this problem is related to the following location:
at public java.util.List game.view.gui.controller.jaxb.Map.getCountries()
...

Welche "Annotation" ist falsch? Bzw. sollte geändert werden? Oder liegt der Fehler eigentlich woanders?

Danke schonmal für die Hilfe.

MfG
baxbear
 
Zuletzt bearbeitet:

foerster7891

Aktives Mitglied
Danke für die Hilfe - war aber wo anders der Fehler.

Ich hab bei @XmlAccessorType() den falschen Typ gewählt.
Da muss XmlAccessType.PUBLIC_MEMBER rein. Geht jetzt. (gerade erst herausgefunden)

Danke trotzdem nochmal an alle die geholfen haben.

MfG
baxbear
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
8u3631984 jaxb XML Mapper - Root Element mit Attribut XML & JSON 20
W jaxws jaxb wsdl Java-Klassen generieren und binding.xml verwenden XML & JSON 1
Rakshan Unmarshalling multiple namespaces with jaxb XML & JSON 0
B JAXB und HTML XML & JSON 1
E JAXB und java.nio.file.Path XML & JSON 4
W jaxb-api XML Feld nicht gesendet setzt das Defaultvalue nicht XML & JSON 3
S Muss ich bei JAXB immer noch eine zusaetzliche List-Wrapper Klasse erstellen wenn ich mehrere Objekte serialisieren will..? XML & JSON 1
S JAXB mit mehreren zusammenhängenden .xsd-Files XML & JSON 0
N JAXB: Überflüssiges Wrapper-Tag für Map-Einträge XML & JSON 0
D JAXB mit Map und Color XML & JSON 2
K JAXB-XML unvollständig XML & JSON 1
K JAXB Unmarshelling XML & JSON 1
E JAXB und abstrakte Klasse(n) XML & JSON 0
B JAXB - Unmarshal -> Kinder bekommen und die Kinder von den Kinder XML & JSON 7
B JAXB - Marshal ArrayList XML & JSON 2
B JAXB - java.util.Locale does not have a no-arg default constructor XML & JSON 2
B JAXB-Fehler bei REST-Api XML & JSON 0
M JAXB HashMap Dynamisches Laden XML & JSON 0
M JAXB @XMLID und @XMLIDREF, wie Daten hinzufügen XML & JSON 2
P JAXB-Problem XML & JSON 1
A JAXB: XMLMixed generieren XML & JSON 0
R [JAXB] XmlRootElement und XmlType gemeinsam nutzen XML & JSON 0
I XML to Object - Mapping mit JAXB 1.0 XML & JSON 1
L JAXB - Generischen Wert mit Liste belegen XML & JSON 1
M XML-Datei mit JAXB und 2 Namespaces XML & JSON 0
K JAXB Annotation @XMLRootElement vererben XML & JSON 0
F JAXB Unmarshal - Kein "default Constructor" XML & JSON 2
F.S.WhiTeY JAXB: Schema nicht "erben" XML & JSON 2
S Jaxb Unmarshalling Problem XML & JSON 4
S JAXB - Any Elementliste - wie Werte verändern? XML & JSON 4
R JAXB: A cycle is detected in the object graph. This will cause infinitely deep XML XML & JSON 6
M JAXB versucht abstrakte Klasse zu erzeugen XML & JSON 7
M JAXB: automatisches Groß schreiben Property XML & JSON 9
C Projekt - JAXB, EMF oder doch DOM? XML & JSON 4
C JAXB: XML-Elemente einlesen und als XML-Attribute ausgeben XML & JSON 7
R sax, stax, jdom, jaxb? List von Objekten speichern und laden XML & JSON 6
J JAXB: Mehrmals abspeichern XML & JSON 3
D XML Einlesen mit JaxB XML & JSON 4
W JAXB Binding customization XML & JSON 4
L JAXB und Interfaces XML & JSON 4
S Problem with JAXB unmarshalling classes that have the same name in @XmlRootElement XML & JSON 2
eykarhorn JAXB namespace attribut aus rootelement entfernen XML & JSON 2
nrg JAXB - nor any of its super class is known to this context XML & JSON 3
S aus XML mit JAXB zu Baumstruktur XML & JSON 3
nrg JAXB generell auf XMLs übertragbar XML & JSON 22
Landei JAXB: Wert von übergeordneten Element XML & JSON 4
B PropertyChangeListener generieren mit JAXB (xjc) XML & JSON 3
G JAXB und verschachtelte Elemente? XML & JSON 6
G JAXB XML-Attribute feststellen XML & JSON 4
S JAXB 2 und JSR 303 XML & JSON 11
M [JAXB] @XmlAnyElement namespace XML & JSON 4
R JAXB Unmarshal XML & JSON 2
J JAXB und ArrayList XML & JSON 4
Landei Jpa2 -> jaxb??? XML & JSON 9
M JAXB - HashMap XML & JSON 1
dzim JAXB-Unmarshalling ignoriert/löscht Einträge aus XML - oder lässt sie verschwinden XML & JSON 3
S JAXB 2 und Java Annotationen/Interfaces generieren XML & JSON 3
ruutaiokwu jaxb eclipse plugin... XML & JSON 3
K JAXB: Klassen mit Annotation Lesen/Schreiben XML XML & JSON 3
R JAXB ausgewählte Felder XML & JSON 10
TiME-SPLiNTER JAXB: com.sun.xml.bind.v2.ContextFactory XML & JSON 3
V JAXB und leere Listen XML & JSON 2
L compareto(), equals() in JAXB generierten Dateien XML & JSON 3
D jaxb validierung/verification vor marshalling XML & JSON 3
J JAXB mit GregorianCalendar XML & JSON 4
HombreDelMundo JAXB can't handle interfaces XML & JSON 4
N Individuelles Wrapper-Element um Collection mit JAXB XML & JSON 6
B JAXB Unmarshalling mehrerer Objekte XML & JSON 2
V JAXB schema 2 java XML & JSON 3
B JPA + JAXB Mapping Problem XML & JSON 2
S Navigieren in unbekannten JAXB-Objecten XML & JSON 2
J JAXB NullPointerException im ContextFinder XML & JSON 6
H JAXB und STAX XML & JSON 2
H JAXB Probleme beim Unmarshalling XML & JSON 3
C Serialisierung mit JAXB XML & JSON 6
K JAXB und Maps -> Marshalling-Problem XML & JSON 6
S JAXB und viele verschachtelte Attribute XML & JSON 1
J JAXB - Map XML & JSON 2
O JAXB generierte Klassen sollen Serializable implementieren XML & JSON 1
aze JaxB: Nullelemente in Array nicht anzeigen XML & JSON 3
turmaline JAXB can't handle interfaces XML & JSON 20
sambalmueslie JAXB - Unmarshall ein XML-Document das aus zwei XSD Definitionen besteht XML & JSON 8
S JAXB und abstrakte Klasse(n) XML & JSON 4
P JAXB: Marshalling XML & JSON 7
aze JaxB Elemente in LinkedHashSet werden nicht wiededergegeben XML & JSON 3
M JAXB: Wie folgendes Konstrukt abbilden? XML & JSON 20
A Jaxb und Interfaces XML & JSON 12
B JaxB und XSD :-) XML & JSON 8
G JAXB - Marshaller - kein Rückgabewert XML & JSON 2
N XML will nicht weder JAXB noch XStream XML & JSON 8
F Zugriff auf durch JAXB erzeugte Object-Struktur... XML & JSON 6
C Java-Imports bei Jaxb XML & JSON 8
F Marshaling eines JAXB Objektes worin ein anderes JAXB Objekt eingeschlossen ist XML & JSON 6
K JAXB, Vererbung und Codegeneration XML & JSON 2
M XmlRootElement und JAXB XML & JSON 4
R JAXB: Aus einem Vector oder List XML Datei erstellen XML & JSON 1
G jaxb Vector (oder ähnliches) von Elementen generieren XML & JSON 6
M Jaxb Annotationen, Wert als XML Element XML & JSON 2
J JCheckbox abfragen und serialisieren mit JAXB 2.0 XML & JSON 15
F JAXB erste schritte XML & JSON 6

Ähnliche Java Themen

Neue Themen


Oben