我不能使XStream工作,我不知道为什么。我在一个Maven项目,JRE-11,MVC模型,XStream 1. 4. 18。我是法国人顺便说一句。提前感谢。我只是把一个例子与UE类,但我想这样做与“Classe”和“Creneau”。我尝试了“xstream.alias”,但没有工作。
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Archi</groupId>
<artifactId>Archi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.18</version>
</dependency>
</dependencies>
</project>
Archi.java
package controlleur;
import com.thoughtworks.xstream.XStream;
import modele.*;
import vue.*;
public class Archi {
public static void main(String[] args) {
Classe classe = new Classe("IATIC5", 2020, 2021);
UE ue = new UE("ARC", "EU-Archi");
Creneau creneau = new Creneau(9, 11, 2021, 20, 22);
Fenetre fenetre = new Fenetre();
XStream xstream = new XStream();
String xml = xstream.toXML(ue);
System.out.println(xml);
Controlleur controlleur = new Controlleur(classe, ue, creneau, fenetre);
}
}
Controller.java
package controlleur;
import modele.*;
import vue.*;
public class Controlleur {
public Controlleur(Classe classe, UE ue, Creneau creneau, Fenetre fenetre) {
fenetre.affiche(classe, ue, creneau);
}
}
UE.java
package modele;
import java.util.UUID;
public class UE {
private String id = UUID.randomUUID().toString(), sigle, nomination;
public UE(String sigle, String nomination) {
this.sigle = sigle;
this.nomination = nomination;
}
//All getter, setter and toString
}
错误文本
Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: No converter available
---- Debugging information ----
message : No converter available
type : modele.UE
converter : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
message[1] : Unable to make field private java.lang.String modele.UE.id accessible: module archi does not "opens modele" to module xstream
-------------------------------
at xstream@1.4.18/com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType(DefaultConverterLookup.java:88)
at xstream@1.4.18/com.thoughtworks.xstream.XStream$1.lookupConverterForType(XStream.java:472)
at xstream@1.4.18/com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:48)
at xstream@1.4.18/com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
at xstream@1.4.18/com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
at xstream@1.4.18/com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
at xstream@1.4.18/com.thoughtworks.xstream.XStream.marshal(XStream.java:1243)
at xstream@1.4.18/com.thoughtworks.xstream.XStream.marshal(XStream.java:1232)
at xstream@1.4.18/com.thoughtworks.xstream.XStream.toXML(XStream.java:1205)
at xstream@1.4.18/com.thoughtworks.xstream.XStream.toXML(XStream.java:1192)
at archi/controlleur.Archi.main(Archi.java:17)
1条答案
按热度按时间axr492tv1#
我有同样的问题,我发现我的项目出了什么问题。
我正在用XStream开发一个在XML中具有数据持久性的JavaFX。当试图读取文件时,我遇到了同样的问题。
为了解决这个问题,我做了以下工作:
module-info.java
)注意:
MODULE
是您正在使用的模块。