enumeratum-mongodb


License

License

Categories

Categories

MongoDB Data Databases
GroupId

GroupId

com.github.alonsodomin
ArtifactId

ArtifactId

enumeratum-mongodb_2.12
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

enumeratum-mongodb
enumeratum-mongodb
Project URL

Project URL

https://github.com/alonsodomin/enumeratum-mongodb
Project Organization

Project Organization

com.github.alonsodomin
Source Code Management

Source Code Management

https://github.com/alonsodomin/enumeraum-mongodb

Download enumeratum-mongodb_2.12

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.11
org.mongodb.scala : mongo-scala-driver_2.12 jar 2.9.0
com.beachape : enumeratum_2.12 jar 1.5.15

test (4)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.30
org.slf4j : slf4j-simple jar 1.7.30
org.scalatest : scalatest_2.12 jar 3.1.1
com.github.simplyscala : scalatest-embedmongo_2.12 jar 0.2.4

Project Modules

There are no modules declared in this project.

Enumeratum MongoDB

Build Status License Maven Central

Extension for Enumeratum and official MongoDB Scala Driver

Getting started

Add the following to your build.sbt:

libraryDependencies += "com.github.alonsodomin" %% "enumeratum-mongodb" % <version>

Usage

Define an enumerated value following the guidelines stated in the Enumeratum documentation:

import enumeratum._
import enumeratum.mongodb._

sealed trait ShirtSize extends EnumEntry
object ShirtSize extends Enum[ShirtSize] with MongoDBEnum[ShirtSize] {
  case object Small  extends ShirtSize
  case object Medium extends ShirtSize
  case object Large  extends ShirtSize

  val values = findValues
}

To make it compatible with MongoDB Driver, we need to mix-in the MongoDBEnum trait into our enum definition as shown above, that will provide with the MongoDB codec generation code required to be abe to use this enum.

To have the codec available when communicating with MongoDB, we need to define a CodecRegistry as follows:

val enumCodecRegistry = CodecRegistry.fromProviders(ShirtSize.bsonCodecProvider)

Versions

Version
0.1.1