Skip to content

Update documentation to show how to create an ALPS serving controller for profile purposes. #1038

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
gregturn opened this issue Aug 4, 2019 · 3 comments
Assignees
Labels
in: documentation Reference documentation in: mediatypes Media type related functionality type: enhancement
Milestone

Comments

@gregturn
Copy link
Contributor

gregturn commented Aug 4, 2019

Problem:

Create a web controller method that returns Alps. It will typically produce either application/json or application/hal+json. Change the produces clause to ALPS_JSON_VALUE, and things fall apart.

@GetMapping(value = "/hypermedia/items/profile", produces = MediaTypes.ALPS_JSON_VALUE)
public Alps profile() {
	return alps() //
			.descriptor(Collections.singletonList(descriptor() //
					.id(Item.class.getSimpleName() + "-representation") //
					.descriptor(Arrays.stream(Item.class.getDeclaredFields()) //
							.map(field -> descriptor() //
									.name(field.getName()) //
									.type(Type.SEMANTIC) //
									.build()) //
							.collect(Collectors.toList())) //
					.build())) //
			.build();
}

A Spring REST Docs test method like this...

@Test
void findProfile() {
	this.webTestClient.get().uri("/hypermedia/items/profile") //
			.accept(MediaTypes.ALPS_JSON) //
			.exchange() //
			.expectStatus().isOk() //
			.expectBody() //
			.consumeWith(document("profile", //
					preprocessResponse(prettyPrint())));
}

...will produce this type of stack error:

org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/json' not supported for bodyType=java.util.LinkedHashMap<?, ?>
	at org.springframework.web.reactive.function.BodyInserters.unsupportedError(BodyInserters.java:368) ~[spring-webflux-5.2.0.BUILD-20190802.092224-620.jar:5.2.0.BUILD-SNAPSHOT]
	at org.springframework.web.reactive.function.BodyInserters.lambda$writeWithMessageWriters$11(BodyInserters.java:358) ~[spring-webflux-5.2.0.BUILD-20190802.092224-620.jar:5.2.0.BUILD-SNAPSHOT]
	at java.util.Optional.orElseGet(Optional.java:267) ~[na:1.8.0_212]
@gregturn gregturn added in: infrastructure Build infrastructure and dependency upgrades in: mediatypes Media type related functionality type: bug labels Aug 4, 2019
@gregturn gregturn added this to the 1.0.0.RC2 milestone Aug 4, 2019
@gregturn
Copy link
Contributor Author

Turns out, since there are no custom serializers/deserializers to register, there is nothing to do except possibly update documentation illustrating how to publish your own profile.

@gregturn gregturn changed the title Ensure ALPS_JSON is also registered when using @EnableHypermediaSupport Update documentation to show how to create an ALPS serving controller for profile purposes. Aug 12, 2019
@gregturn gregturn added in: documentation Reference documentation and removed in: infrastructure Build infrastructure and dependency upgrades labels Aug 12, 2019
gregturn added a commit that referenced this issue Aug 13, 2019
@gregturn gregturn modified the milestones: 1.0.0.RC2, 1.0.0.RELEASE Sep 4, 2019
@gregturn
Copy link
Contributor Author

gregturn commented Sep 9, 2019

Thanks to #1064, the scope of this has shrunk from a bug to a simple request to update documentation and add some more tests.

@gregturn gregturn assigned odrotbohm and gregturn and unassigned odrotbohm Sep 9, 2019
@gregturn gregturn modified the milestones: 1.0.0.RELEASE, 1.0.0.RC3 Sep 16, 2019
gregturn added a commit that referenced this issue Sep 26, 2019
Also make the ALPS types support deserialization using @JsonCreator-based private constructor calls.
@gregturn
Copy link
Contributor Author

Resolved via f15740f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: documentation Reference documentation in: mediatypes Media type related functionality type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants