Included are some supporting classes that I've found helpful when building a Dropwizard service that communicates with MongoDB.
For other useful Dropwizard reusables (not related to MongoDB), take a look at starwizard-core.
If you are interested in using a lightweight MongoDB DAO abstraction with support for POJO mapping using Jackson, take a look at stardao.
Add the following to your POM:
<properties>
<starwizard.version>0.1.3</starwizard.version>
...
</properties>
<dependencies>
<dependency>
<groupId>io.stardog.starwizard</groupId>
<artifactId>starwizard-mongodb</artifactId>
<version>${starwizard.version}</version>
</dependency>
...
</dependencies>
This Dropwizard health check checks that your service has basic connectivity to a MongoDB database, by issuing the MongoDB ping command.
To use it, just register it in your app's health checks in your run()
method.
env.healthChecks().register("mongo", injector.getInstance(MongoHealthCheck.class));
swagger-core, by default, gets confused by the ObjectId
MongoDB type, and will expose it as a total mess of an object containing the timestamp, machine identifier, etc. Normally in your APIs, you want ObjectId
to be considered a string for external consumption.
This ModelConverter
will force ObjectIds to be treated as Strings for Swagger's purposes.
To use it, add it to the ModelConverters
instance:
ModelConverters.getInstance().addConverter(new ObjectIdConverter());