Skip to content

Add CURIE support for embedded resources #34

@irieill

Description

@irieill

In my reading of the HAL-draft it is perfectly valid to use CURIE syntax for the link relation type of embedded properties. To serialize the following "hypertext cache pattern" JSON:

{
  "_links": {
    "curies": [
      {
        "href": "http://example.org/relations/foo/{rel}",
        "templated": true,
        "name": "foo"
      }
    ],
    "foo:bars": [
      {
        "href": "http://example.org/bars/248875bd-c7e1-357f-8473-450cc49a8308"
      }
    ],
    "self": {
      "href": "http://example.org/bars"
    }
  },
  "_embedded": {
    "foo:bars": [
      {
        "_links": {
          "self": {
            "href": "http://example.org/bars/248875bd-c7e1-357f-8473-450cc49a8308"
          }
        },
        "uuid": "248875bd-c7e1-357f-8473-450cc49a8308"
      }
    ]
  },
  "count": 1
}

Currently someone needs to provide a fixed CURIE value for the embedded resource:

@Resource
@Curie(prefix = "foo", href = "http://example.org/relations/foo/{rel}"
public class Bars {

  private HALLink self;
  private List<Bar> barResources;
  private List<HALLink> barLinks;
  private Integer count;

  public (HALLink self, List<Bar> bars) {
    this.self = Objects.requireNonNull(self);
    this.barResources = Objects.requireNonNull(bars);
    this.barLinks = bars.stream().map(bar -> bar.getSelf()).collect(Collectors.toList());
    this.count = Integer.valueOf(bars.size());
  }

  @Link
  public HALLink getSelf() {
    return this.self;
  }

  @EmbeddedResource(value = "foo:bars")
  public List<Bar> getBarResources() {
    return this.barResources;
  }


  @Link(curie = "foo", value = "bars")
  public List<HALLink> getBarLinks() {
    return this.barLinks;
  }

  public Integer getCount() {
    return this.count;
  }

}

It would be nice if someone could use @EmbeddedResource(curie = "foo", value = "bars") (as with @Link).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions