Skip to content

Commit 349674e

Browse files
committed
Adapt tests for Jackson ParameterNamesModule
Closes gh-27511
1 parent 2f43f77 commit 349674e

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -229,9 +229,22 @@ public void decodeWithNullLiteral() {
229229
StepVerifier.create(result).expectComplete().verify();
230230
}
231231

232-
@Test
232+
@Test // gh-27511
233233
public void noDefaultConstructor() {
234234
Flux<DataBuffer> input = Flux.from(stringBuffer("{\"property1\":\"foo\",\"property2\":\"bar\"}"));
235+
236+
testDecode(input, BeanWithNoDefaultConstructor.class, step -> step
237+
.consumeNextWith(o -> {
238+
assertThat(o.getProperty1()).isEqualTo("foo");
239+
assertThat(o.getProperty2()).isEqualTo("bar");
240+
})
241+
.verifyComplete()
242+
);
243+
}
244+
245+
@Test
246+
public void codecException() {
247+
Flux<DataBuffer> input = Flux.from(stringBuffer("["));
235248
ResolvableType elementType = ResolvableType.forClass(BeanWithNoDefaultConstructor.class);
236249
Flux<Object> flux = new Jackson2JsonDecoder().decode(input, elementType, null, Collections.emptyMap());
237250
StepVerifier.create(flux).verifyError(CodecException.class);

spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,15 @@ public void writeSubTypeList() throws Exception {
498498
assertThat(result).contains("\"number\":123");
499499
}
500500

501-
@Test
501+
@Test // gh-27511
502502
public void readWithNoDefaultConstructor() throws Exception {
503503
String body = "{\"property1\":\"foo\",\"property2\":\"bar\"}";
504504
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
505505
inputMessage.getHeaders().setContentType(MediaType.APPLICATION_JSON);
506-
assertThatExceptionOfType(HttpMessageConversionException.class).isThrownBy(() ->
507-
converter.read(BeanWithNoDefaultConstructor.class, inputMessage))
508-
.withMessageStartingWith("Type definition error:");
506+
BeanWithNoDefaultConstructor bean =
507+
(BeanWithNoDefaultConstructor)converter.read(BeanWithNoDefaultConstructor.class, inputMessage);
508+
assertThat(bean.property1).isEqualTo("foo");
509+
assertThat(bean.property2).isEqualTo("bar");
509510
}
510511

511512
@Test

0 commit comments

Comments
 (0)