【问题标题】:How do I generate a List<List<Double>> with apache cxf如何使用 apache cxf 生成 List<List<Double>>
【发布时间】:2017-05-19 10:03:54
【问题描述】:

我正在尝试使用 apache cxf 生成 List&lt;List&lt;Double&gt;&gt;

下面的xsd生成一个List&lt;Double&gt;

<xsd:complexType name="Geometry">
    <xsd:sequence>
        <xsd:element name="type" minOccurs="1" type="xsd:string"/>
        <xsd:element name="coordinates" minOccurs="1">
            <xsd:simpleType>
                <xsd:list>
                    <xsd:simpleType>
                        <xsd:list itemType="xsd:double"/>
                    </xsd:simpleType>
                </xsd:list>
            </xsd:simpleType>
        </xsd:element>
    </xsd:sequence>
</xsd:complexType>

如果我将maxOccurs="unbounded" 添加到元素坐标,我会得到一个List&lt;JAXBElement&lt;List&lt;Double&gt;&gt;&gt; coordinates

如何生成List&lt;List&lt;Double&gt;&gt;

【问题讨论】:

    标签: java apache xsd cxf


    【解决方案1】:

    架构说坐标可以包含一个双精度列表,这基本上意味着一个双精度列表。

    改变 maxoccurs="unbounded" 会显着改变 XML

    <coordinates>1 2 3</coordinates>
    

    现在可以

    <coordinates>1</coordinates>
    <coordinates>2 3</coordinates>
    

    到目前为止生成的内容看起来正确,您想让 XML 看起来像什么?

    【讨论】:

    • 实际上我正在使用 wadl2java 生成一个 java 类,它代表我的 web 服务的输出。这是针对我的网络服务响应中的 geoJson 字段:{"type":"", "coordinates":[[0;0,0.0],[0.0,0.0]]}
    • 好的,我想我遗漏了一些东西,您尝试使用 xml 模式 (XSD) 作为元数据生成 json 输出。 XSD 是从哪里来的?如果输出是 json,你有 json 架构吗?
    猜你喜欢
    • 2021-12-26
    • 1970-01-01
    • 2014-07-24
    • 2015-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    相关资源
    最近更新 更多