Add support for "application/*+x-protobuf" media type

See gh-34645

Signed-off-by: Kamil Doroszkiewicz <kamil.doroszkiewicz@gmail.com>
This commit is contained in:
Kamil Doroszkiewicz
2025-03-25 10:37:29 +01:00
committed by Brian Clozel
parent 79a793e44c
commit c1839938ea
3 changed files with 20 additions and 8 deletions

View File

@@ -48,12 +48,14 @@ class ProtobufHttpMessageConverterTests {
private ExtensionRegistry extensionRegistry = mock();
private Msg testMsg = Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(123).build()).build();
private MediaType testPlusProtoMediaType = MediaType.parseMediaType("application/vnd.example.public.v1+x-protobuf");
@Test
void canRead() {
assertThat(this.converter.canRead(Msg.class, null)).isTrue();
assertThat(this.converter.canRead(Msg.class, ProtobufHttpMessageConverter.PROTOBUF)).isTrue();
assertThat(this.converter.canRead(Msg.class, this.testPlusProtoMediaType)).isTrue();
assertThat(this.converter.canRead(Msg.class, MediaType.APPLICATION_JSON)).isTrue();
assertThat(this.converter.canRead(Msg.class, MediaType.TEXT_PLAIN)).isTrue();
}
@@ -62,6 +64,7 @@ class ProtobufHttpMessageConverterTests {
void canWrite() {
assertThat(this.converter.canWrite(Msg.class, null)).isTrue();
assertThat(this.converter.canWrite(Msg.class, ProtobufHttpMessageConverter.PROTOBUF)).isTrue();
assertThat(this.converter.canRead(Msg.class, this.testPlusProtoMediaType)).isTrue();
assertThat(this.converter.canWrite(Msg.class, MediaType.APPLICATION_JSON)).isTrue();
assertThat(this.converter.canWrite(Msg.class, MediaType.TEXT_PLAIN)).isTrue();
}

View File

@@ -42,12 +42,14 @@ class ProtobufJsonFormatHttpMessageConverterTests {
JsonFormat.parser(), JsonFormat.printer());
private final Msg testMsg = Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(123).build()).build();
private MediaType testPlusProtoMediaType = MediaType.parseMediaType("application/vnd.examle.public.v1+x-protobuf");
@Test
void canRead() {
assertThat(this.converter.canRead(Msg.class, null)).isTrue();
assertThat(this.converter.canRead(Msg.class, ProtobufHttpMessageConverter.PROTOBUF)).isTrue();
assertThat(this.converter.canRead(Msg.class, this.testPlusProtoMediaType)).isTrue();
assertThat(this.converter.canRead(Msg.class, MediaType.APPLICATION_JSON)).isTrue();
assertThat(this.converter.canRead(Msg.class, MediaType.TEXT_PLAIN)).isTrue();
}
@@ -56,6 +58,7 @@ class ProtobufJsonFormatHttpMessageConverterTests {
void canWrite() {
assertThat(this.converter.canWrite(Msg.class, null)).isTrue();
assertThat(this.converter.canWrite(Msg.class, ProtobufHttpMessageConverter.PROTOBUF)).isTrue();
assertThat(this.converter.canWrite(Msg.class, this.testPlusProtoMediaType)).isTrue();
assertThat(this.converter.canWrite(Msg.class, MediaType.APPLICATION_JSON)).isTrue();
assertThat(this.converter.canWrite(Msg.class, MediaType.TEXT_PLAIN)).isTrue();
}