[英]recursive xsd generates java class with Objects instead of the given Type
So, I have an object which can contain a list of Objects of that type. 因此,我有一个对象,可以包含该类型的对象列表。 I wrote an XSD which looks something like this:
我写了一个看起来像这样的XSD:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="myNamespace" elementFormDefault="qualified">
<complexType name="BinModel">
<sequence>
<element type="string" name="min" />
<element type="string" name="max" />
<element type="string" name="fieldname" />
<element type="int" name="defaultValue" />
<element xmlns:ref="BinModel" name="innerBins" maxOccurs="unbounded" minOccurs="0" />
</sequence>
</complexType>
<element name="AllBins">
<complexType>
<sequence>
<element type="string" name="fieldnames" maxOccurs="unbounded" minOccurs="0"/>
<element type="int" name="defaultValue"/>
<element xmlns:type="BinModel" name="outerBins" maxOccurs="unbounded" minOccurs="0" />
</sequence>
</complexType>
</element>
</schema>
It produces two java classes, BinModel and AllBins respectively, but in each of those classes, even though I specify that they contain a list of type BinModel
, it produces a List of type Object
. 它产生两个Java类,分别是BinModel和AllBins,但是在每个这些类中,即使我指定它们都包含
BinModel
类型的列表,它BinModel
产生Object
类型的List。
How do I generate a class which has a List of BinModel
s? 如何生成具有
BinModel
列表的BinModel
?
So I realized something was wrong when it took me adding xmlns
before type
and ref
in order to not show errors in the editor. 所以我意识到当我在
type
和ref
之前添加xmlns
以便不显示编辑器中的错误时出现了问题。 I looked at another xsd for a recursively defined Object somewhere else in my stupidly huge codebase to try and find a solution and discovered two things. 我在愚蠢的巨大代码库中的另一个地方查看了另一个xsd,以找到一个递归定义的对象,以尝试找到解决方案并发现了两件事。 1. We were defining our own namespace 2. We referenced our own objects within that namespace.
1.我们定义了自己的命名空间。2.在该命名空间中引用了我们自己的对象。
So the corrected code looks something like this: 因此,更正后的代码如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:myProject="projectNamespace" targetNamespace="myNamespace" elementFormDefault="qualified">
<complexType name="BinModel">
<sequence>
<element type="string" name="min" />
<element type="string" name="max" />
<element type="string" name="fieldname" />
<element type="int" name="defaultValue" />
<element type="myProject:BinModel" name="innerBins" maxOccurs="unbounded" minOccurs="0" />
</sequence>
</complexType>
<element name="AllBins">
<complexType>
<sequence>
<element type="string" name="fieldnames" maxOccurs="unbounded" minOccurs="0"/>
<element type="int" name="defaultValue"/>
<element type="myProject:BinModel" name="outerBins" maxOccurs="unbounded" minOccurs="0" />
</sequence>
</complexType>
</element>
</schema>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.