Bonsoir,

J'ai un fichier XML de ressemble à ca:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8"?>
	<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
	<categories>
	<category id="1" xlink:href="http://localhost/prestashop/api/categories/1"/>
	<category id="2" xlink:href="http://localhost/prestashop/api/categories/2"/>
	<category id="3" xlink:href="http://localhost/prestashop/api/categories/3"/>
	<category id="4" xlink:href="http://localhost/prestashop/api/categories/4"/>
	</categories>
</prestashop>
J'ai crée deux classe pour la structure xml que voici:
Class Prestashop
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
 
 
import java.util.List;
 
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
 
 
@XmlRootElement(name = "Prestashop")
class Prestashop{
 
	@XmlElement(required = true)
	private List <Categories> categories;
 
	public List <Categories> getCategories() {
		return categories;
	}
 
	public void setCategories(List <Categories> categories) {
		this.categories = categories;
	}
 
}
Class Categories
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
 
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
 
 
public class Categories {
 
	@XmlElement(required = true)
	public String category;
 
	@XmlAttribute(name = "id", required = true)
	int id;
 
	public String getCategory() {
		return category;
	}
	public void setCategory(String category) {
		this.category = category;
	}
 
}

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
JAXBContext jaxbContext = JAXBContext.newInstance(Prestashop.class);
			Prestashop prestashop = (Prestashop) jaxbContext.createUnmarshaller().unmarshal(new TestStreaming().cat());
Lorsque je lance mon Main j'obtiens deux erreurs de ce type:

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
Class has two properties of the same name "categories"
this problem is related to the following location:
at public java.util.List Prestashop.getCategories()
at Prestashop
this problem is related to the following location:
at private java.util.List Prestashop.categories
at Prestashop
Class has two properties of the same name "category"
this problem is related to the following location:
at public java.lang.String Categories.getCategory()
at Categories
at private java.util.List Prestashop.categories
at Prestashop
this problem is related to the following location:
at public java.lang.String Categories.category
at Categories
at private java.util.List Prestashop.categories
at Prestashop


at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at TestUnmarshalPrestashop.main(TestUnmarshalPrestashop.java:12)


Je pense que j'ai mal structurer mes class. Pouvez vous m'aider à trouver l'erreur svp?

Merci