我有以下Rest课程
object MyRest extends RestHelper {
override implicit val formats =
net.liftweb.json.DefaultFormats + BigDecimalSerializer
serveJx[MyRest.AutoJsonXmlAble] {
case "api" :: "static" :: "item" :: itemId :: Nil Get _ =>
auto(
new Item(
itemId,
"Name",
"Disc",
BigDecimal(5),
true,
12,
12
)
)
}
}
和Model类如下
case class Item(id: String, name: String,
description: String,
price: BigDecimal, taxable: Boolean,
weightInGrams: Int, qnty: Int)
但是当我运行应用程序时,我得到了输出
curl -H"Accept:application/json" http://localhost:8080/api/static/item/1234
{
"id":"1234",
"name":"Name",
"description":"Disc",
"price":5.0,
"taxable":true,
"weightInGrams":12,
"qnty":12
}
curl -H"Accept:application/xml" http://localhost:8080/api/static/item/1234
<?xml version="1.0" encoding="UTF-8"?>
<id>1234</id>
这里有什么问题?我试图在XML和JSON之间使用自动转换。我在哪里可以获得有关电梯中休息模块的详细信息?
更新 我认为问题在于root标签。从上面的XML输出可以看出,没有root标签。任何人都可以指导我如何使用serveJx获得root标签?