Skip to content

Support for empty arrays in the embedded representations #16

@slayful

Description

@slayful

As far as I've checked it's not possible to add a sub representation which will yield an empty array in the "_embedded" field.

I've modified the repositories to enable this.

Trying to serialise this representation:

    String href = "customer/123456";
    ReadableRepresentation party = newBaseResource(href)
                                       .withLink("ns:users", BASE_URL + href + "?users")
                                       .withRepresentation("ns:users",  representationFactory
                                           .newRepresentation("1")
                                           .setEmptySubRepresentation(true));

will yield the following JSON:

{
  "_links" : {
    "curies" : [ {
      "href" : "https://example.com/apidocs/ns/{rel}",
      "name" : "ns",
      "templated" : true
    }, {
      "href" : "https://example.com/apidocs/role/{rel}",
      "name" : "role",
      "templated" : true
    } ],
    "self" : {
      "href" : "https://example.com/api/customer/123456"
    },
    "ns:parent" : {
      "href" : "https://example.com/api/customer/1234",
      "name" : "bob",
      "title" : "The Parent",
      "hreflang" : "en"
    },
    "ns:users" : {
      "href" : "https://example.com/api/customer/123456?users"
    }
  },
  "_embedded" : {
    "ns:users" : [ ]
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions