java - Eclipse Maven XStream - 无法使字段可访问 - 模块不会“打开模型”到模块 xstream
问题描述
我不能让 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);
}
}
控制器.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)
解决方案
推荐阅读
- json - 带有 JSON 参数的 HttpPost 在 ASP.NET Core 3 中不起作用
- angular - 当我使用本地库模块时测试失败
- reactjs - React Native:跨应用程序用户协作文档
- eclipse - 如何在 NatTable 中选择行单元格时选择整列?
- angular - Angular 8:刷新基本网址时页面重定向到主页
- android - Android Greendao - 分组和排序
- java - 在这种情况下如何避免 ConcurrentModificationException?
- r - 无法在 Mac OSX catalina 上使用 Vegan 包
- php - 我想将所有子文件夹页面重定向到子域我该怎么做?
- cypress - 赛普拉斯配置插值