Last active
August 29, 2015 14:01
-
-
Save dirkraft/cac9c5b357f1e78d2aa6 to your computer and use it in GitHub Desktop.
Scala jackson jersey-client: Arcane incantation that gets Jersey client serializing scala types. dependencies: 'org.scala-lang:scala-library:2.10.3', 'com.fasterxml.jackson.module:jackson-module-scala_2.10:2.3.3', 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.3.3', 'com.sun.jersey:jersey-client:1.18.1'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val client = Client.create(new DefaultClientConfig( | |
classOf[ScalaJacksonJsonProvider] | |
)) | |
class ScalaJacksonJsonProvider extends JacksonJsonProvider(new ObjectMapper().registerModule(DefaultScalaModule)) {} | |
// sample usages | |
val stringResult = client.resource("http://localhost:8080/service").get(new GenericType[String](){}) | |
val jacksonResult = client.resource("http://localhost:8080/service").post(new GenericType[JsonNode](){}, """ | |
{ | |
"literal": "json", | |
"stuff": [ | |
{ | |
"things": 5 | |
} | |
] | |
} | |
""") | |
val mapResult = client.resource("http://localhost:8080/service").post(new GenericType[Map[String, _]](){}, Map( | |
"key" -> "value", | |
"numbers" -> List(1, 2, 3, 5), | |
"nested" -> Map( | |
"inner" -> "circle" | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment