Akka HTTP:如何将Json格式响应解组为域对象

[英]Akka HTTP: How to unmarshal Json format response into domain objects


I am trying out Akka HTTP, and I have created a service that returns a Json Array of domain objects in HttpResponse. In the client I want to convert it to a Source of domain objects so it can be consumed by the subsequent Flows and Sinks.

我正在尝试Akka HTTP,我创建了一个服务,在HttpResponse中返回一个域对象的Json数组。在客户端中,我想将其转换为域对象的源,以便后续的流和接收器可以使用它。

Referring to the Json Support section: http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0/scala/http/common/json-support.html

参考Json支持部分:http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0/scala/http/common/json-support.html

I have done the necessary to define implicit RootJsonReader etc, but I don’t know how to make use of the FromEntityUnmarshaller.

我已经完成了定义隐式RootJsonReader等的必要,但我不知道如何使用FromEntityUnmarshaller。

My code is here: https://github.com/charlesxucheng/akka-http-microservice

我的代码在这里:https://github.com/charlesxucheng/akka-http-microservice

It is based on the akka-http-microservice activator template. Service2.scala is my server implementation and is working. AkkaHttpClient.scala is the client implementation and it is incomplete.

它基于akka-http-microservice激活器模板。 Service2.scala是我的服务器实现,并且正在运行。 AkkaHttpClient.scala是客户端实现,它不完整。

To build, pls use Gradle as the build.sbt is not up-to-date.

要构建,请使用Gradle作为build.sbt不是最新的。

Thanks.

谢谢。

1 个解决方案

#1


1  

Akka HTTP now has the ability to do this transparently.

Akka HTTP现在能够透明地执行此操作。

http://doc.akka.io/docs/akka-http/current/scala/http/common/json-support.html

http://doc.akka.io/docs/akka-http/current/scala/http/common/json-support.html


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2015/10/01/2f88da803220f02dfd38f5800b5baf06.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号