unexpected element (uri:"", local:"Group"). Expected elements are <{}group>
Run Code Online (Sandbox Code Playgroud)
从xml解组时遇到异常
JAXBContext jc = JAXBContext.newInstance(Group.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
Group group = (User)unmarshaller.unmarshal(new File("group.xml"));
Run Code Online (Sandbox Code Playgroud)
组类没有任何注释,group.xml只包含数据.
什么都可能是原因?
尝试使用jaxb将xml响应转换为java对象时,我收到以下错误
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://SOMETHING/doc/2006-03-01/", local:"Name"). Expected elements are <{}Name>,<{}IsTruncated>,<{}MaxKeys>,<{}Contents>,<{}Prefix>,<{}Marker>
Run Code Online (Sandbox Code Playgroud)
这是我的XML:
<ListBucketResult xmlns="http://something/doc/2006-03-01/">
<Name>test2</Name>
<Prefix/>
<Marker/>
<MaxKeys>3</MaxKeys>
<IsTruncated>false</IsTruncated>
<Contents>
<Key>metadata.xml</Key>
<LastModified>2012-09-04T08:29:36.000Z</LastModified>
<ETag>6b836fd43c402681506926b2248ec418</ETag>
<Size>3258</Size>
<StorageClass>STANDARD</StorageClass>
</Contents>
</ListBucketResult>
Run Code Online (Sandbox Code Playgroud)
我的java对象类就是这样的
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"name",
"prefix",
"marker",
"maxKeys",
"isTruncated",
"contents"
})
@XmlRootElement(name = "ListBucketResult")
public class ListBucketResult {
@XmlElement(name = "Name", required = true)
protected String name;
@XmlElement(name = "Prefix", required = true)
protected String prefix;
@XmlElement(name = "Marker", required = true)
protected String marker;
@XmlElement(name = "MaxKeys")
protected int …Run Code Online (Sandbox Code Playgroud) 我正试图从Java 8迁移到Java 10,并面临以下问题与JOOQ codegen Maven插件.
我的环境:
pom.xml中:
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.11.5</version>
<executions>
<execution>
...
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen</artifactId>
<version>3.11.5</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
<version>3.11.5</version>
</dependency>
</dependencies>
<configuration>
<configurationFile>target/my_conf.xml</configurationFile>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
my_conf.xml如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
<jdbc>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://${host}/${db_name}</url>
<user>${user_username}</user>
<password>${pwds}</password>
</jdbc>
<generator>
<database>
<name>org.jooq.meta.mysql.MySQLDatabase</name> …Run Code Online (Sandbox Code Playgroud)