-
Notifications
You must be signed in to change notification settings - Fork 738
Closed
Description
My system:
- springbootversion
2.0.1.RELEASE - springCloudVersion
Finchley.M9 - java 1.8
- org.springframework.boot:spring-boot-starter-webflux
- org.javamoney:moneta:1.2.1
- org.springframework.restdocs:spring-restdocs-webtestclient
custom SimpleModule
@Bean
public SimpleModule moneyModule() {
return new MoneyModule();
}
public MoneyModule() {
addSerializer(Money.class, new MoneySerializer());
addValueInstantiator(Money.class, new MoneyInstantiator());
}
Integration test
@RunWith(SpringRunner.class)
@ActiveProfiles("integTest")
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class XxxxHandlerTest{
@Autowired
WebTestClient webTestClient;
@Rule
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();
@Autowired
ApplicationContext context;
@Before
public void init() throws Exception {
this.webTestClient = WebTestClient.bindToApplicationContext(this.context)
.configureClient()
.baseUrl("http://local.com.cn")
.filter(WebTestClientRestDocumentation
.documentationConfiguration(this.restDocumentation)
.operationPreprocessors()
.withResponseDefaults(prettyPrint())
)
.build();
}
@Test
public void testStoreVoucherEntry() {
Operator mockUser = Operator.builder().name("张会计").id(ObjectId.get().toString()).build();
List<AccountingEntry> accountingEntries = Arrays.asList(AccountingEntry.builder()
.code("12121").summary("销售票据").debit(Money.of(100, "CNY"))
.credit(Money.of(100, "CNY")).build());
VoucherPost voucherPost = VoucherPost.builder().operator(mockUser)
.accountingEntries(accountingEntries).build();
webTestClient.post()
.uri(mockUrl)
.body(BodyInserters.fromObject(voucherPost))
.exchange().expectStatus().isOk();
}
The above code test error :
org.springframework.core.codec.DecodingException: JSON decoding error: Cannot construct instance of `org.javamoney.moneta.Money` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `org.javamoney.moneta.Money` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
When I remove the following code,test code is working properly
this.webTestClient = WebTestClient.bindToApplicationContext(this.context)
.configureClient()
.baseUrl("http://local.com.cn")
.filter(WebTestClientRestDocumentation
.documentationConfiguration(this.restDocumentation)
.operationPreprocessors()
.withResponseDefaults(prettyPrint())
)
.build();
I guess the webtestclient's configuration has caused it to ignore the custom jackson module, so I would like to know how to solve this problem. Maybe there is no problem at all, but my configuration is wrong. Please give me some advice. Thank you.
Metadata
Metadata
Assignees
Labels
No labels