javaodataolingo

How to read a collection of entities with complex properties in olingo?


I am roughly following this Tutorial from apache olingo page. I want to read a collection of entities that have complex properties.

Setting up the provider, I get the following output when accessing 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>

Which seems to be ok for me (is it?). But wenn I try to read a collection of my entities accessing http://localhost:8080/api/odata/MyEntities, I get the return message

Cannot find type with name: My.Namespace.MyComplexType

And stepping into the code reveals a thrown expection in the readEntityCollection method of the processor when entityCollection is called on the serializer.

I must miss an important point, because it seems to me that My.Namespace.MyComplexType is clearly defined.


Solution

  • Although the exception was thrown in the processor, the error did not have anything to do with serialization.

    The complex type MyComplexType could not be found, because only getEntityType(final FullQualifiedName entityTypeName) was overridden in the EdmProvider, but not getComplexType(final FullQualifiedName complexTypeName). olingo seems to search for types by calling these methods.

    After overriding this method all data was properly displayed.