Skip to content
This repository was archived by the owner on Mar 22, 2021. It is now read-only.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

33 Commits

Repository files navigation

valuetype

Build StatusDownload

A scala micro-library introducing Value Type (tiny type) trait and some subtraits for simple types like String, Int, Boolean and BigDecimal. It also contains tooling for creating Play JSON format and PathBinders for derived types.

Play JSON format

importplay.api.libs.json.Jsonimportplay.api.libs.json.Json.{toJson, fromJson}
importuk.gov.voa.valuetype.IntValueimportuk.gov.voa.valuetype.play.formats.ValueTypeFormatcaseclassMyIntValue(value: Int) extendsIntValueimplicitvalmyIntValueFormat=ValueTypeFormat.format(MyIntValue.apply)
toJson(MyIntValue(2))
fromJson(Json.parse("2"))

Play PathBinders

importplay.api.mvc.PathBindableimportuk.gov.voa.valuetype.IntValueimportuk.gov.voa.valuetype.play.binders.ValueTypePathBinder._importscala.util.TrycaseclassMyIntValue(value: Int) extendsIntValueimplicitvalintValueParser: (String) =>Try[MyIntValue] = value =>Try {
MyIntValue(value.toInt)
}
valintValueBinder= implicitly[PathBindable[MyIntValue]]
intValueBinder.bind("key", "1")
intValueBinder.unbind("key", MyIntValue(1))

Installing

Include the following dependency in your SBT build

resolvers +=Resolver.bintrayRepo("hmrc", "releases")
libraryDependencies +="uk.gov.hmrc"%%"valuetype"%"<INSERT VERSION>"

License

This code is open source software licensed under the Apache 2.0 License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages