我大致遵循apache olingo页面上的Tutorial。我想阅读具有复杂属性的实体的集合。

设置提供程序,访问http://localhost:8080/api/odata/$metadata时得到以下输出:

<?xml version="1.0" encoding="UTF-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
    <edmx:DataServices>
        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="My.Namespace">
            <EntityType Name="MyEntity">
                <Key>
                    <PropertyRef Name="id"/>
                </Key>
                <Property Name="id" Type="Edm.String"></Property>
                <Property Name="name" Type="Edm.String"></Property>
                <Property Name="description" Type="Edm.String"></Property>
                <Property Name="complexProp" Type="My.Namespace.MyComplexType"></Property>
            </EntityType>
            <ComplexType Name="MyComplexType">
                <Property Name="id" Type="Edm.String"></Property>
                <Property Name="name" Type="Edm.String"></Property>
            </ComplexType>
            <EntityContainer Name="Container">
                <EntitySet Name="MyEntities" EntityType="My.Namespace.MyEntity"></EntitySet>
            </EntityContainer>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>


这对我来说似乎可以(是吗?)。但是我们尝试读取访问http://localhost:8080/api/odata/MyEntities的实体的集合,但收到返回消息

Cannot find type with name: My.Namespace.MyComplexType


当在序列化程序上调用readEntityCollection时,进入代码可以发现处理器的entityCollection方法中引发了期望。

我必须错过一个要点,因为在我看来My.Namespace.MyComplexType是明确定义的。

最佳答案

尽管在处理器中引发了异常,但该错误与序列化无关。

找不到复杂类型MyComplexType,因为在EdmProvider中仅覆盖了getEntityType(final FullQualifiedName entityTypeName),而没有覆盖getComplexType(final FullQualifiedName complexTypeName)olingo似乎通过调用这些方法来搜索类型。

覆盖此方法后,所有数据均正确显示。

09-10 20:48