草庐IT

JAXB_FORMATTED_OUTPUT

全部标签

java.util.List 是一个接口(interface),JAXB 不能处理接口(interface)

在尝试部署我的应用程序时,我似乎遇到了以下异常:Causedby:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:2countsofIllegalAnnotationExceptionsjava.util.Listisaninterface,andJAXBcan'thandleinterfaces.thisproblemisrelatedtothefollowinglocation:atjava.util.Listatprivatejava.util.Listfoobar.alkohol.register.webservi

java - 使用 JAXB 解码/编码 List<String>

我正在尝试创建一个非常简单的REST服务器。我只有一个返回字符串列表的测试方法。代码如下:@GET@Path("/test2")publicListtest2(){Listlist=newVector();list.add("a");list.add("b");returnlist;}Itgivesthefollowingerror:SEVERE:AmessagebodywriterforJavatype,classjava.util.Vector,andMIMEmediatype,application/octet-stream,wasnotfoundIwashopingJAXBha

java - 使用 JAXB 解码/编码 List<String>

我正在尝试创建一个非常简单的REST服务器。我只有一个返回字符串列表的测试方法。代码如下:@GET@Path("/test2")publicListtest2(){Listlist=newVector();list.add("a");list.add("b");returnlist;}Itgivesthefollowingerror:SEVERE:AmessagebodywriterforJavatype,classjava.util.Vector,andMIMEmediatype,application/octet-stream,wasnotfoundIwashopingJAXBha

java - 生成实现接口(interface)的 JAXB 类

我目前正在使用JAXB生成java类以解码XML。现在我想创建一个与第一个非常相似的新模式,并让生成的类实现相同的接口(interface)。例如,我有两个架构文件,它们用相似的标签定义XML:成人.xsdkid.xsd使用JAXB和XJC我想生成两个类文件:publicclassAdultimplementsPerson{...publicStringgetName(){...}publicintgetAge(){...}publicStringgetJob{...}}publicclassKidimplementsPerson{...publicStringgetName(){..

java - 生成实现接口(interface)的 JAXB 类

我目前正在使用JAXB生成java类以解码XML。现在我想创建一个与第一个非常相似的新模式,并让生成的类实现相同的接口(interface)。例如,我有两个架构文件,它们用相似的标签定义XML:成人.xsdkid.xsd使用JAXB和XJC我想生成两个类文件:publicclassAdultimplementsPerson{...publicStringgetName(){...}publicintgetAge(){...}publicStringgetJob{...}}publicclassKidimplementsPerson{...publicStringgetName(){..

Java 泛型 : why is this output possible?

我有这门课:classMyClass{Nn=(N)(newInteger(8));}我想得到这些输出:System.out.println(newMyClass().n);System.out.println(newMyClass().n.getClass());第一个System.out.println()语句的输出:8第二个System.out.println()语句的输出:java.lang.ClassCastException:java.lang.Integer(inmodule:java.base)cannotbecasttojava.lang.Long(inmodule:j

Java 泛型 : why is this output possible?

我有这门课:classMyClass{Nn=(N)(newInteger(8));}我想得到这些输出:System.out.println(newMyClass().n);System.out.println(newMyClass().n.getClass());第一个System.out.println()语句的输出:8第二个System.out.println()语句的输出:java.lang.ClassCastException:java.lang.Integer(inmodule:java.base)cannotbecasttojava.lang.Long(inmodule:j

java - 为什么 JAXB 不为列表生成 setter

当我从XSD生成JAXB类时,具有maxOccurs="unbounded"的元素会获得为它们生成的getter方法,但没有setter方法,如下所示:/***Getsthevalueoftheelement3property.***Thisaccessormethodreturnsareferencetothelivelist,*notasnapshot.Thereforeanymodificationyoumaketothe*returnedlistwillbepresentinsidetheJAXBobject.*Thisiswhythereisnotasetmethodfort

java - 为什么 JAXB 不为列表生成 setter

当我从XSD生成JAXB类时,具有maxOccurs="unbounded"的元素会获得为它们生成的getter方法,但没有setter方法,如下所示:/***Getsthevalueoftheelement3property.***Thisaccessormethodreturnsareferencetothelivelist,*notasnapshot.Thereforeanymodificationyoumaketothe*returnedlistwillbepresentinsidetheJAXBobject.*Thisiswhythereisnotasetmethodfort

java - 如何仅从 XML 生成 JAXB 类

我需要从不提供架构的xml生成类。我知道这几乎没用,但事实是我们有xml,它是结构化的,我们应该能够从xml创建模型。过去我是手工完成的,但是我正在使用的当前xml文档非常大,我的时间可能会更好地用于构建可以满足我需要的东西。但是,我猜它已经完成了,我只是找不到它。任何指针? 最佳答案 有许多可用的工具(快速的google搜索应该会找到一些)可以从XML生成XSD,假设几乎所有内容都是字符串类型。您应该能够使用该XSD运行JAXB来获取类。这是onlinetool让你这样做。这是一个屏幕截图: