我想使用akka http实现restful http服务。[法]收货和做某事
{
"user": {
"userid": 123,
"reqid": "abcdef",
"username": "张三"
},
"article": {
"atype": 1,
"fromdate": "2017-06-27"
},
"tags": {
"fixtags": [
{ "t":"t1", "w": 30 },
{ "t":"t2", "w": 20 },
{ "t":"t3", "w": 10 },
{ "t":"t4", "w": 50 }
],
"atags": [
{ "t":"t5", "w": 30 },
{ "t":"t6", "w": 20 }
]
}
}案例类
case class Article(atype: Int, fromdate: String)
case class Tag(t: String, w: Double)
case class FixTags(fixtags: List[Tag])
case class ATags(atags: List[Tag])
//case class Tags( fixtags: List[Map[String, Float]], atags: List[Map[String, Float]] )
case class Tags(fixtags: FixTags, atags: ATags)
case class AUserInfo(user: User, article: Article, tags: Tags)
implicit val userFormat1 = jsonFormat3( User )
implicit val artFormat1 = jsonFormat2( Article )
implicit val tagFormat1 = jsonFormat2( Tag )
implicit val ftagFormat1 = jsonFormat1( FixTags )
implicit val atagFormat1 = jsonFormat1( ATags )
implicit val tagsFormat1 = jsonFormat2( Tags )
implicit val userFormat = jsonFormat3( AUserInfo )路线:
path( "rcmd" / LongNumber ) {
userid =>
post {
entity( as[AUserInfo] ) { userinfo =>do sth}asAUserInfo将报告错误:
请求内容格式错误:字段“fixtags”%中期望的对象
或者:
找不到参数um: akka.http.scaladsl.unmarshalling.Unmarshaller的隐式值
有人能帮我吗?
发布于 2017-07-13 03:46:47
我已经发现了错误:因为我的json字符串格式不适合我的case类。我将case类更改为下面,并修复该错误:
//case class FixTags(fixtags: List[Tag])
//case class ATags(atags: List[Tag])
case class Tags(fixtags: List[Tag], atags: List[Tag])https://stackoverflow.com/questions/45070842
复制相似问题