scala-rison


License

License

Categories

Categories

Scala Languages
GroupId

GroupId

com.github.takezoe
ArtifactId

ArtifactId

scala-rison_2.12
Last Version

Last Version

0.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

scala-rison
scala-rison
Project URL

Project URL

https://github.com/takezoe/scala-rison
Project Organization

Project Organization

com.github.takezoe
Source Code Management

Source Code Management

https://github.com/takezoe/scala-rison

Download scala-rison_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.takezoe/scala-rison_2.12/ -->
<dependency>
    <groupId>com.github.takezoe</groupId>
    <artifactId>scala-rison_2.12</artifactId>
    <version>0.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.takezoe/scala-rison_2.12/
implementation 'com.github.takezoe:scala-rison_2.12:0.0.4'
// https://jarcasting.com/artifacts/com.github.takezoe/scala-rison_2.12/
implementation ("com.github.takezoe:scala-rison_2.12:0.0.4")
'com.github.takezoe:scala-rison_2.12:jar:0.0.4'
<dependency org="com.github.takezoe" name="scala-rison_2.12" rev="0.0.4">
  <artifact name="scala-rison_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.takezoe', module='scala-rison_2.12', version='0.0.4')
)
libraryDependencies += "com.github.takezoe" % "scala-rison_2.12" % "0.0.4"
[com.github.takezoe/scala-rison_2.12 "0.0.4"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.8
org.scala-lang.modules : scala-parser-combinators_2.12 jar 1.1.1
org.wvlet.airframe : airframe-surface_2.12 jar 0.79
org.wvlet.airframe : airframe-codec_2.12 Optional jar 0.79
com.typesafe.play : play-json_2.12 Optional jar 2.6.10

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.1

Project Modules

There are no modules declared in this project.

scala-rison Build Status Maven Central License

Rison parser for Scala

Installation

libraryDependencies += "com.github.takezoe" %% "scala-rison" % "0.0.4"

Usage

import com.github.takezoe.rison._

// case class
case class Player(name: String, age: Int)

// parse
RisonParser.parse("(name:Lacazette,age:27)") match {
  case Right(node) => {
    // to Scala Map
    println(node.toScala) // => Map(name -> Lacazette, age -> 27)
    // to Case class
    println(node.asInstanceOf[ObjectNode].to[Player]) // => Player(Lacazette, 27)
  }
  case Left(error) => println(error)
}

// convert from Case class
val node1: RisonNode = RisonNode.fromScala(Player("Lacazette", 27))
println(node1.toRisonString) // => (name:Lacazette',age:27)

// convert from Scala Map
val node2: RisonNode = RisonNode.fromScala(
  Map("name" -> "Alexandre Lacazette", "twitter" -> "@LacazetteAlex")
)
println(node2.toRisonString) // => (name:'Alexandre Lacazette',twitter:'@LacazetteAlex')

// URL encode
val encoded: String = node2.toUrlEncodedString
println(encoded) // => (name:'Alexandre+Lacazette',twitter:'@LacazetteAlex')

// o-rison
val orison: ObjectNode = RisonParser.parseObject("name:Lacazette,age:27")
println(orison.toObjectString) // => name:Lacazette,age:27

// a-rison
val arison: ArrayNode = RisonParser.parseArray("Lacazette,Aubameyang,Ozil")
println(arison.toArrayString) // => Lacazette,Aubameyang,Ozil

Play JSON integration

By using play-json with scala-rison, you can convert Rison and Json each other and also use play-json's the ability of type-safe case class conversion.

You need to add following play-json dependency additionally to use pla-json integration:

libraryDependencies += "com.typesafe.play" %% "play-json" % "2.6.10"
// Json to Rison
val json1 = Json.parse("""{"name":"Lacazette","age":27}""")
val rison1 = PlayRison.fromPlayJson(json1)
println(rison1) // => (name:Lacazette,age:27)

// Rison to Json
val rison2 = RisonParser.parse("(name:Lacazette,age:27)").right.get
val json2 = PlayRison.toPlayJson(rison2)
println(json2) // => {"name":"Lacazette","age":27}

Versions

Version
0.0.4
0.0.3
0.0.2
0.0.1