在使用Java(Jaxb)构建XML时出现问题。

huangapple go评论79阅读模式
英文:

Problem with building Xml with Java (Jaxb)

问题

所以我想要构建一个 XML 文档当我尝试编译它时在这个文件第23243031行中会出现错误错误消息是类型的非法开始

package legoset;

import lombok.Data;
import movie.YearAdapter;

import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.net.URL;
import java.time.Year;
import java.util.List;
import java.util.Set;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = "name", "theme", "subtheme", "year", "pieces")
@Data
public class LegoSet {
    private String name;
    private String theme;
    private String subtheme;
    private int pieces;

    @XmlElementWrapper(name = "minifigs")
    @XmlElement(name = "minifig")
    private List<Minifig> minifigs;

    private Weight weight;
    private URL url;

    @XmlElementWrapper(name = "tags")
    @XmlElement(name = "tag")
    private Set<String> tags;

    @XmlJavaTypeAdapter(YearAdapter.class)
    private Year year;

    @XmlAttribute
    private String number;
}
英文:

So I want to build an Xml document. When I try to compile it drops error in this file (line 23, 24, 30, 31). The error message is: illegal start of type.

package legoset;

import lombok.Data;
import movie.YearAdapter;

import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.net.URL;
import java.time.Year;
import java.util.List;
import java.util.Set;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = &quot;name&quot;, &quot;theme&quot;, &quot;subtheme&quot;, &quot;year&quot;, &quot;pieces&quot;)
@Data
public class LegoSet {
    private String name;
    private String theme;
    private String subtheme;
    private int pieces;

    @XmlElementWrapper(name = &quot;minifigs&quot;);
    @XmlElement(name = &quot;minifig&quot;);
    private List&lt;Minifig&gt; minifigs;

    private Weight weight;
    private URL url;

    @XmlElementWrapper(name = &quot;tags&quot;);
    @XmlElement(name = &quot;tag&quot;);
    private Set&lt;String&gt; tags;

    @XmlJavaTypeAdapter(YearAdapter.class)
    private Year year;

    @XmlAttribute
    private String number;
}

答案1

得分: 0

请删除注释后的分号。

例如:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = "name", "theme", "subtheme", "year", "pieces")
@Data
public class LegoSet {
    private String name;
    private String theme;
    private String subtheme;
    private int pieces;

    @XmlElementWrapper(name = "minifigs")
    @XmlElement(name = "minifig")
    private List<Minifig> minifigs;

    private Weight weight;
    private URL url;

    @XmlElementWrapper(name = "tags")
    @XmlElement(name = "tag")
    private Set<String> tags;

    @XmlJavaTypeAdapter(YearAdapter.class)
    private Year year;

    @XmlAttribute
    private String number;
}
英文:

Remove the semicolon after annotation.

e.g.

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = &quot;name&quot;, &quot;theme&quot;, &quot;subtheme&quot;, &quot;year&quot;, &quot;pieces&quot;)
@Data
public class LegoSet {
    private String name;
    private String theme;
    private String subtheme;
    private int pieces;

    @XmlElementWrapper(name = &quot;minifigs&quot;)
    @XmlElement(name = &quot;minifig&quot;)
    private List&lt;Minifig&gt; minifigs;

    private Weight weight;
    private URL url;

    @XmlElementWrapper(name = &quot;tags&quot;)
    @XmlElement(name = &quot;tag&quot;)
    private Set&lt;String&gt; tags;

    @XmlJavaTypeAdapter(YearAdapter.class)
    private Year year;

    @XmlAttribute
    private String number;
}

huangapple
  • 本文由 发表于 2020年4月4日 00:00:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/61015838.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定