问题描述
我有一个Flat对象,它具有3个FastMoney属性,当我调用终结点从邮递员创建新Flat时,没有错误发生,但是当我尝试在测试中运行时,出现了这个问题:
Type deFinition error: [simple type,class org.javamoney.moneta.FastMoney]
这是测试方法:
@Test
public void createFlat() throws Exception {
Landlord landlord = new Landlord();
String uri = "/flat/create";
Flat flat = new Flat(FLAT_TITLE,FLAT_CITY,FLAT_ADDRESS,FLAT_PRICEDECIMAL,FLAT_UTILITIESDECIMAL,FLAT_DETAILS,FLAT_NUMBEROFROOMS,FLAT_NUMBEROFbedS,FLAT_WIFI,FLAT_INTERNETSPEED,FLAT_RENOVATE,FLAT_FURNISHED,FLAT_RENTORBUY,"EUR",landlord,FLAT_AVAILABLEFROM);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE,false);
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
String requestJson=ow.writeValueAsstring(flat);
MvcResult mvcResult = mvc.perform(mockmvcRequestBuilders.post(uri)
.contentType(new MediaType(MediaType.APPLICATION_JSON.getType(),MediaType.APPLICATION_JSON.getSubtype(),Charset.forName("utf8"))).content(requestJson)).andReturn();
int status = mvcResult.getResponse().getStatus();
Assert.assertEquals(200,status);
Flat flat1 = flatRepository.findByTitle(FLAT_TITLE);
Assert.assertEquals(flat1.getNumberOfbeds(),FLAT_NUMBEROFbedS);
}
这些是对象:
// removed another properties
private FastMoney price;
private FastMoney utilities;
private FastMoney total;
public Flat(BigDecimal price,BigDecimal utilities ){
this.price=FastMoney.of(price,Monetary.getCurrency(currencyUnit));
this.utilities=FastMoney.of(utilities,Monetary.getCurrency(currencyUnit));
this.total=this.price.add(this.utilities);
}
一种选择是使用ObjectMapper并将其“解析”为JSON,但是它不起作用,我该如何解决?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)