Skip to content

Create builder to simplify assembling representations. #1273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

gregturn
Copy link
Contributor

Original issue: #864.
Related issue: #193.

gregturn added a commit that referenced this pull request Apr 17, 2020
Make a fluent API that lets you construct various RepresentationModel objects (EntityModel, CollectionModel, or complex embedded).

Original pull request: #1273.
Related issue: #193.
@gregturn gregturn force-pushed the issue/HATEOAS-864 branch from 6573152 to 8544cff Compare April 17, 2020 16:27
gregturn added a commit that referenced this pull request Apr 24, 2020
Defines a basic Model.Builder interface that works for all hypermedia types with option for specific mediatypes to implement a customized version.

* Implement a DefaultModelBuilder that only focuses on entities and links. This allows building some of the simplest representations that are supported by all formats.
* Implement a HalModelBuilder that supports the same basic operations but also includes HAL-specific embed() and previewFor() as HAL syntax sugar.

By having a basic interface, other media types are free to either A) go along with the default format, or B) implement their own implementation, with mediatype-specific operators.

Also, introduces a preferredMediaTypes attribute in RepresentationModel so various serializers can warn if the user is attempting to serialize a HAL-specific representation as, say, Collection+JSON.

Original pull request: #1273.
Related issue: #193.
@gregturn gregturn force-pushed the issue/HATEOAS-864 branch from 80bdc0f to 660bbb4 Compare April 24, 2020 19:13
gregturn added a commit that referenced this pull request Apr 24, 2020
Defines a basic Model.Builder interface that works for all hypermedia types with option for specific mediatypes to implement a customized version.

* Implement a DefaultModelBuilder that only focuses on entities and links. This allows building some of the simplest representations that are supported by all formats.
* Implement a HalModelBuilder that supports the same basic operations but also includes HAL-specific embed() and previewFor() as HAL syntax sugar.

By having a basic interface, other media types are free to either A) go along with the default format, or B) implement their own implementation, with mediatype-specific operators.

Also, introduces a preferredMediaTypes attribute in RepresentationModel so various serializers can warn if the user is attempting to serialize a HAL-specific representation as, say, Collection+JSON.

Original pull request: #1273.
Related issue: #193.
@gregturn gregturn force-pushed the issue/HATEOAS-864 branch from 660bbb4 to e59251a Compare April 24, 2020 19:20
gregturn added a commit that referenced this pull request Apr 24, 2020
…els.

* Implement a `DefaultModelBuilder` that only focuses on entities and links. This allows building some of the simplest representations that are suppoerted by all formats.
* Implement a `HalModelBuilder` that supports the same basic operations but also includes HAL-specific embed() and previewFor() as HAL syntax sugar.

`DefaultModelBuilder` allows defining "simple" formats (single-item or collection at an aggregate root). A `builder()` static helper is provided to create an instance of this type.

`HalModelBuilder` allows going into HAL-specific details, like `embed()` and `previewFor`, where you can specify an entity AND it's link relation. This results in a representation that will generate an "_embedded" entry. It also marks the `RepresntationModel` object with a HAL/HAL-FORMS "preferredMediaType", allowing other serializers to either log warnings, or fail.

Having the interface grants hypermedia authors the ability to create their own customized model builders as they see fit.

Also, introduces a preferredMediaTypes attribute in RepresentationModel so various serializers can warn if the user is attempting to serialize a HAL-specific representation as, say, Collection+JSON.

Original pull request: #1273.
Related issue: #193.
@gregturn gregturn force-pushed the issue/HATEOAS-864 branch from e59251a to c14919d Compare April 24, 2020 21:34
* Implement a `DefaultModelBuilder` that only focuses on entities and links. This allows building some of the simplest representations that are suppoerted by all formats.
* Implement a `HalModelBuilder` that supports the same basic operations but also includes HAL-specific embed() and previewFor() as HAL syntax sugar.

`DefaultModelBuilder` allows defining "simple" formats (single-item or collection at an aggregate root). A `builder()` static helper is provided to create an instance of this type.

`HalModelBuilder` allows going into HAL-specific details, like `embed()` and `previewFor`, where you can specify an entity AND it's link relation. This results in a representation that will generate an "_embedded" entry. It also marks the `RepresntationModel` object with a HAL/HAL-FORMS "preferredMediaType", allowing other serializers to either log warnings, or fail.

Having the interface grants hypermedia authors the ability to create their own customized model builders as they see fit.

Also, introduces a preferredMediaTypes attribute in RepresentationModel so various serializers can warn if the user is attempting to serialize a HAL-specific representation as, say, Collection+JSON.

Original pull request: #1273.
Related issue: #193.
@gregturn gregturn force-pushed the issue/HATEOAS-864 branch from c14919d to 26b074f Compare April 24, 2020 21:35
@gregturn
Copy link
Contributor Author

@odrotbohm

I retooled things into Model.Builder based upon how WebClient.Builder is put together. I just put the DefaultModelBuilder and HalModelBuilder into the Model class. Then I topped it off with a builder() static helper as well as a hal() static helper.

I rewrote the test cases to get rid of MockMVC etc., and put ALL the related test cases into one class, so you can see them at a glance.

odrotbohm added a commit that referenced this pull request May 7, 2020
HalModelBuilder expose HAL-idiomatic API to set up representations. That includes embeds, previews and syntactic sugar around the inclusion of potentially empty collections as embeds.

Related tickets: #175, #193, #270, #920.
Original pull request: #1273.
@odrotbohm odrotbohm closed this May 7, 2020
@odrotbohm odrotbohm self-assigned this May 7, 2020
@odrotbohm odrotbohm added in: core Core parts of the project in: mediatypes Media type related functionality type: enhancement labels May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core parts of the project in: mediatypes Media type related functionality type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants