开发者

JSON-RPC to SOAP and back to JSON: Mapping JSON objects to non-trivial SOAP messages

I'm trying to create a server that takes JSON-RPC requests from a client, transforms those into non-trivial SOAP requests to a SOAP server, then takes the SOAP response and sends the client a transformed JSON response. The responses that come back from the SOAP server are potentially very complicated and nested, and I'm trying to map the XML fields to flatter JSON. The mappi开发者_JAVA技巧ngs wont be 1:1. As an example, we may get back a sequence of codes in the SOAP response that we want to return in the JSON response as their values from a database.

I'm willing to use whatever languages or technologies are best appropriate, so is there anything out there that already solves this problem or can help?


scalaxb can turn SOAP into case classes and interfaces. lift-json can turn case classes into json.

The scalaxb-generated code would be 1:1. See wsdl 1.1 support.

If you want to map the case classes into some other intermediate case classes, you can do that first. Then you can apply lift-json to turn them into json automatically

scala> import net.liftweb.json._
scala> import net.liftweb.json.Serialization.{read, write}
scala> implicit val formats = Serialization.formats(NoTypeHints)
scala> val ser = write(Child("Mary", 5, None))
scala> read[Child](ser)
res1: Child = Child(Mary,5,None)

or manually

scala> import net.liftweb.json._
scala> implicit val formats = DefaultFormats // Brings in default date formats etc.
scala> case class Child(name: String, age: Int, birthdate: Option[java.util.Date])
scala> case class Address(street: String, city: String)
scala> case class Person(name: String, address: Address, children: List[Child])
scala> val json = parse(...)
scala> json.extract[Person] 
res0: Person = Person(joe,Address(Bulevard,Helsinki),List(Child(Mary,5,Some(Sat Sep 04 18:06:22 EEST 2004)), Child(Mazy,3,None)))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜