on 2024 Aug 12 5:33 PM
I need create an api that will return structure that one of is fields is table base on structure that one of his fields is table too.
implementing $expended entity is too much complicated
what i do now is return a string
and in the front end i do json parse ( and it is not comfort because i need run over all boolean values and convert 'x' to true... )
can i return json object without instriction of flat entity?
There is no way to do that in OData V2, other than what you have already discovered: tunnel your deep structure in a JSON string.
OData V2 does not support collection-valued properties, which is one of the many reasons why we moved forward to OData V4 ten years ago.
Maybe you want to switch to V4.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
With OData V4 you can model deep json objects with complex types and collections of complex types:
<EntityType Name="X">
<Key>
<PropertyRef Name="id"/>
</Key>
<Property Name="id" Type="Edm.String" Nullable="false"/>
<Property Name="data" Type="test.Y"/>
<Property Name="deepData" Type="Collection(test.Y)" Nullable="true"/>
</EntityType>
<ComplexType Name="Y">
<Property Name="foo" Type="Edm.String"/>
<Property Name="bar" Type="test.Z"/>
<Property Name="baz" Type="Collection(test.Z)" Nullable="true"/>
</ComplexType>
<ComplexType Name="Z">
<Property Name="x" Type="Edm.String"/>
<Property Name="y" Type="Edm.String"/>
</ComplexType>
In JSON "data" will be an object, "deepData" an array of objects, and in both cases the objects have properties of type string, object, and array of object, respectively.
In CAP CDS the corresponding model would be
entity X {
key id : String;
data : Y;
deepData : many Y;
}
type Y {
foo : String;
bar : Z;
baz : many Z;
}
type Z {
x : String;
y : String;
}
Does this answer your question?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
68 | |
10 | |
10 | |
10 | |
10 | |
8 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.