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.
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"))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))Include the following dependency in your SBT build
resolvers +=Resolver.bintrayRepo("hmrc", "releases")
libraryDependencies +="uk.gov.hmrc"%%"valuetype"%"<INSERT VERSION>"This code is open source software licensed under the Apache 2.0 License.