Skip to content
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

#1061 - Reenable default codecs for WebFlux configuration. #1064

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,14 @@ static class HypermediaWebFluxConfigurer implements WebFluxConfigurer {
@Override
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {

CodecConfigurer.CustomCodecs customCodecs = configurer.customCodecs();

this.hypermediaTypes.forEach(hypermedia -> {

MimeType[] mimeTypes = hypermedia.getMediaTypes().toArray(new MimeType[0]);

ObjectMapper objectMapper = hypermedia.configureObjectMapper(this.mapper.copy());
customCodecs.encoder(new Jackson2JsonEncoder(objectMapper, mimeTypes));
customCodecs.decoder(new Jackson2JsonDecoder(objectMapper, mimeTypes));
MimeType[] mimeTypes = hypermedia.getMediaTypes().toArray(new MimeType[0]);

configurer.customCodecs().encoder(new Jackson2JsonEncoder(objectMapper, mimeTypes));
configurer.customCodecs().decoder(new Jackson2JsonDecoder(objectMapper, mimeTypes));
});

customCodecs.encoder(CharSequenceEncoder.allMimeTypes());
customCodecs.decoder(StringDecoder.allMimeTypes());

configurer.registerDefaults(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* @author Greg Turnquist
* @author Oliver Drotbohm
*/
class Jackson2CollectionJsonModule extends SimpleModule {
public class Jackson2CollectionJsonModule extends SimpleModule {

private static final long serialVersionUID = -6540574644565592709L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
* @author Greg Turnquist
* @author Oliver Gierke
*/
class Jackson2HalFormsModule extends SimpleModule {
public class Jackson2HalFormsModule extends SimpleModule {

private static final long serialVersionUID = -4496351128468451196L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

/**
* @author Greg Turnquist
Expand Down Expand Up @@ -258,12 +259,17 @@ void registeringAllHypermediaTypesShouldAllowCreatingThroughAllFormats() {
* @see #728
*/
@Test
void callingForUnregisteredMediaTypeShouldFail() {
void callingForUnregisteredMediaTypeShouldFallBackToJackson() {

setUp(HalWebFluxConfig.class);

this.testClient.get().uri("/").accept(MediaTypes.UBER_JSON).exchange().expectStatus().is4xxClientError()
.returnResult(String.class).getResponseBody().as(StepVerifier::create).verifyComplete();
this.testClient.get().uri("/").accept(MediaTypes.UBER_JSON) //
.exchange() //
.expectStatus().isOk() //
.returnResult(String.class).getResponseBody() //
.as(StepVerifier::create) //
.expectNext("{\"links\":[{\"rel\":\"self\",\"href\":\"/\"},{\"rel\":\"employees\",\"href\":\"/employees\"}]}")
.verifyComplete();
}

/**
Expand Down
Loading