jsoniter-scala


License

License

Categories

Categories

Scala Languages JSON Data jsoniter
GroupId

GroupId

com.github.cerst
ArtifactId

ArtifactId

jsoniter-scala_2.13
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

jsoniter-scala
jsoniter-scala
Project URL

Project URL

https://github.com/cerst/vacade
Project Organization

Project Organization

Constantin Gerstberger
Source Code Management

Source Code Management

https://github.com/cerst/vacade

Download jsoniter-scala_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.cerst/jsoniter-scala_2.13/ -->
<dependency>
    <groupId>com.github.cerst</groupId>
    <artifactId>jsoniter-scala_2.13</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.cerst/jsoniter-scala_2.13/
implementation 'com.github.cerst:jsoniter-scala_2.13:0.1.1'
// https://jarcasting.com/artifacts/com.github.cerst/jsoniter-scala_2.13/
implementation ("com.github.cerst:jsoniter-scala_2.13:0.1.1")
'com.github.cerst:jsoniter-scala_2.13:jar:0.1.1'
<dependency org="com.github.cerst" name="jsoniter-scala_2.13" rev="0.1.1">
  <artifact name="jsoniter-scala_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.cerst', module='jsoniter-scala_2.13', version='0.1.1')
)
libraryDependencies += "com.github.cerst" % "jsoniter-scala_2.13" % "0.1.1"
[com.github.cerst/jsoniter-scala_2.13 "0.1.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.2

provided (1)

Group / Artifact Type Version
com.github.plokhotnyuk.jsoniter-scala : jsoniter-scala-core_2.13 jar 2.2.4

Project Modules

There are no modules declared in this project.

GitHub license Maven Central

Value Class Derivations

Value-class-derivations (vacade) is to reduce boilerplate needed to work with value classes and different libraries.
It supports Scala 2.12 & 2.13.

Usage

Due to breaking changes and compatibility problems, vacade - for the time being - has two release paths (starting with 0.3.0):

Versions following regular semver conventions keeping all dependencies as updated as possible
Versions ending in -1 which pin akka-http at version 10.1.x (due to ecosystem compatibility issues)

Pick one or more target library (depending on release path):

libraryDependencies ++= Seq(
    "com.github.cerst" %% "vacade-akka-http" % vacadeVersion,
    "com.github.cerst" %% "vacade-avro4s" % vacadeVersion,
    "com.github.cerst" %% "vacade-jsoniter-scala" % vacadeVersion
)

Pick imports and derivations as needed:

import com.github.cerst.vacade.akka.http._
import com.githuc.cerst.vacade.avro4s._
import com.githuc.cerst.vacade.jsoniter_scala._
// dependent imports
import akka.http.scaladsl.server.PathMatcher1
import com.github.plokhotnyuk.jsoniter_scala.core.JsonCodec
import com.sksamuel.avro4s.{Decoder, Encoder, SchemaFor}
import io.estatico.newtype.macros.newtype
import io.estatico.newtype.ops._

object types {

  @newtype
  final class ItemId(val asInt: Int)

  object ItemId {

    // null.asInstanceOf is only required for AnyVal value classes due to https://github.com/scala/bug/issues/8097
    // otherwise, you'll get a runtime NullPointerException when the resulting codec is first accessed
    // leave it out for Newtype
    implicit val jsonCodecForItemId: JsonCodec[ItemId] = vcJsonCodec.int(apply)(_.asInt, null.asInstanceOf[ItemId])
    
    // due to a change in Avro4s 4.0, it is unfortunately no longer possible to have a single type implementing Encoder & Decoder
    implicit val (
      encoderForItemId: Encoder[ItemId],
      decoderForItemId: Decoder[ItemId],
      schemaForItemId: SchemaFor[ItemId]
    ) = vcAvro4s(apply)(_.value)

    val pm: PathMatcher1[ItemId] = vcPathMatcher.int(apply)

    def apply(value: Int): ItemId = {
      value.coerce
    }

  }

}

Design Principles

  • Only add features & convenience which is missing from existing libraries
    • i.e. don't provide methods for every single library/ feature out there
  • Don't break with the design on a particular API
    • i.e. don't retrofit implicits if the underlying library does not have them
  • All libraries are configured as Provided
  • All derivations methods are prefixed with vc followed by the name of the target type (e.g. vcJsonCodec)
    • Whenever explicit specification of underlying types is required, the aforementioned methods become objects having said types as method names (e.g. vcJsonCodec.int).
      These objects also document why they are necessary.
  • Implementations should work as consistently as possible for AnyVal and newtype.

Versions

Version
0.1.1
0.1.0