You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@isis.apache.org by Andi Huber <ah...@apache.org> on 2018/04/03 06:50:12 UTC

Re: Rest API - Response with list of viewmodels

Hello Smitha,
I don't think there is any way to 'expand' the nested view-model content
as you described.

You might consider serializing your list of nested view-models into a
base64 encoded String and expose this String as a
(transient/not-persistable) property of your 'ViewModel-A'.

Your REST client then would need to take care of decoding/deserializing
this String.

Cheers, Andi!


On 2018/03/28 12:17:29, Smitha N <sm...@gmail.com> wrote:
> Hello,
>
> I am trying to use REST API in my Apache ISIS application.
>
> I have an action which on invoke should return a response in this format:
>
>
> Result extends Dto{
>
> String type;
> int code;
> List<ViewModel-A> articles;
> }
>
> ViewModel-A extends Dto{
>
> String technology;
> String supplier;
>
> SortedSet<ViewModel-B> sortedModel;
>
> Address address;
>
> }
>
> This is the response I get:
>
> {
> "$$href": "http://localhost:8080/restful/objects/Result/
> "code": 0,
> "articles": [
> {
> "$$href": "http://localhost:8080/restful/objects/ViewModel-A/,
> "$$title": "ViewModel A",
> "$$instanceId": ,
> "address": {
> "rel": "urn:org.restfulobjects:rels/value",
> "href": "http://localhost:8080/restful/objects/Address/",
> "method": "GET",
> "type": "application/json;profile=\"
> urn:org.restfulobjects:repr-types/object\"",
> "title": "Address"
> },
> "supplier": "supplier-name",
> "technology": "technology-name"
> },
> {
> "$$href": "http://localhost:8080/restful/objects/ViewModel-A/,
> "$$title": "ViewModel A",
> "$$instanceId": ,
> "address": {
> "rel": "urn:org.restfulobjects:rels/value",
> "href": "http://localhost:8080/restful/objects/Address/",
> "method": "GET",
> "type": "application/json;profile=\"
> urn:org.restfulobjects:repr-types/object\"",
> "title": "Address"
> },
> "supplier": "supplier-name1",
> "technology": "technology-name1"
> },
> {
> "$$href": "http://localhost:8080/restful/objects/ViewModel-A/,
> "$$title": "ViewModel A",
> "$$instanceId": ,
> "address": {
> "rel": "urn:org.restfulobjects:rels/value",
> "href": "Address",
> "method": "GET",
> "type": "application/json;profile=\"
> urn:org.restfulobjects:repr-types/object\"",
> "title": "Address"
> },
> "supplier": "supplier-name1",
> "technology": "technology-name2"
> }
> ],
> "type": "type"
> }
>
> As it can be seen in the response, even though there are values, the
> ViewModel-B, sortedModel property in ViewModel-A class is not shown.
>
> Is there any better way to retrieve the properties of these nested view
> models (instead of links to these classes)?
> Also I am not sure why the properties of ViewModel-B (sortedModel property
> of ViewModel-A) are not populated.
>
> Please let me know how to resolve this issue. How do we get a more
> flattened structure of the nested class properties in the response?
>
> I am setting Accept request header as
> application/json;profile="urn:org.apache.isis/v1".
>
> When I post this request, I get the response but it doesnot
>
>
>
> Regards
> Smitha
>