Git Product home page Git Product logo

dynamo-mapper's Introduction

Dynamo Mapper

GitHub release (latest by date) javadoc GitHub Workflow Status (branch) GitHub

A simple mapper for converting to and from DynamoDB AttributeValues and POJOs using Jackson.

In development

Dynamo Mapper is still in development. Currently, only single gets, puts, updates, and deletes are supported. More is planned in the future and submissions are welcome.

Installation

Dynamo Mapper is available from Maven Central.

Gradle

implementation 'com.autonomouslogic.dynamomapper:dynamo-mapper:version'

Maven

<dependency>
    <groupId>com.autonomouslogic.dynamomapper</groupId>
    <artifactId>dynamo-mapper</artifactId>
    <version>version</version>
</dependency>

Usage

Dynamo Mapper functions as a wrapper around the existing AWS DynamoDB v2 SDK. First, you need to construct a DynamoDB client object and a Jackson ObjectMapper, and then pass those to the Dynamo Mapper builder. If you do not provide a DynamoDB client or Jackson ObjectMapper, defaults will be used.

var dynamoMapper = DynamoMapper.builder()
    .client(DynamoDbClient.create())
    .objectMapper(new ObjectMapper())
    .tableNameDecorator(decorator) // optional
    .build();

Or, for the asynchronous API:

var asyncDynamoMapper = DynamoAsyncMapper.builder()
    .client(DynamoDbAsyncClient.create())
    .objectMapper(new ObjectMapper())
	.tableNameDecorator(decorator) // optional
    .build();

Defining schemas

Dynamo Mapper relies on Jackson for its serialization. Generally, anything that works in Jackson will work in Dynamo Mapper. Only a few extra annotations are required.

@DynamoTableName("table-name")
public class ModelObject {
	@JsonProperty
	@DynamoPrimaryKey
	private String primaryKey;
	
	@JsonProperty
	private String otherValue;
	
	/* etc. */
}

Getting items

Using the synchronous API:

var item = dynamoMapper.getItemFromPrimaryKey("key-value", ModelObject.class).item();

Using the asynchronous API:

dynamoMapper.getItemFromPrimaryKey("key-value", ModelObject.class).thenAccept(response -> {
	var item = response.item();
});

Putting items

Using the synchronous API:

var item = new ModelObject().setPrimaryKey("key-value");
var response = dynamoMapper.putItemFromKeyObject(item);

Using the asynchronous API:

var item = new ModelObject().setPrimaryKey("key-value");
dynamoMapper.putItemFromKeyObject(item).thenAccept(response -> {
	// etc.
});

Best practices

  • Jackson will include all null values, to prevent this taking up space in DynamoDB, use @JsonInclude(JsonInclude.Include.NON_NULL)
  • To properly serialize BigDecimals, use objectMapper.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN)
  • To encode java.time objects properly, use jackson-datatype-jsr310

Comparison with DynamoDBMapper and DynamoDB Enhanced

The DynamoDBMapper in the v1 AWS SDK and the DynamoDB Enhanced Client in the v2 AWS SDK both provide similar mapping functionality.

This idea for this library was originally created to provide the same mapping as the v1 mapper, but for the v2 SDK, before the enhanced client was released. The v2 SDK now provides this mapping functionality officially, but has a few short-comings. For instance, the annotations must be added to methods and not properties. This makes Lombok models useless. Jackson is a widely used and mature library. with advanced features that will never, and shouldn't, be implemented in the enhanced client.

There are some cons to doing it this way. For instance, it's not possible to have a different schema in the DynamoDB and JSON versions of an object.

Feature Dynamo Mapper DynamoDBMapper (v1) DynamoDb Enhanced Client (v2)
Synchronous API Yes Yes Yes
Asynchronous API Yes No Yes
Lombok compatible Yes Partial? No?

Resources

Versioning

Dynamo Mapper follows semantic versioning.

Code Style

Dynamo Mapper follows Palantir with tabs. Automatic code formatting can be done by running ./gradlew spotlessApply.

License

Dynamo Mapper is licensed under the MIT-0 license.

Status

Type Status
LGTM Language grade: Java Total alerts
CodeClimate Maintainability
SonarCloud Maintainability Rating Code Smells
Libraries.io Libraries.io dependency status for latest release
Snyk Known Vulnerabilities
Codecov codecov
Synatype Lift link

dynamo-mapper's People

Contributors

autonomous-logic-code-bot avatar kennethjor avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar

dynamo-mapper's Issues

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Starting a Gradle Daemon, 4 stopped Daemons could not be reused, use --status for details

Task :buildSrc:processResources NO-SOURCE
Task :buildSrc:generateTestEffectiveLombokConfig
Task :buildSrc:processTestResources NO-SOURCE
Task :buildSrc:generateEffectiveLombokConfig
Task :buildSrc:compileJava
Task :buildSrc:compileGroovy NO-SOURCE
Task :buildSrc:classes
Task :buildSrc:jar
Task :buildSrc:assemble
Task :buildSrc:compileTestJava NO-SOURCE
Task :buildSrc:compileTestGroovy NO-SOURCE
Task :buildSrc:testClasses UP-TO-DATE
Task :buildSrc:test NO-SOURCE
Task :buildSrc:check UP-TO-DATE
Task :buildSrc:build
Task :processResources NO-SOURCE
Task :delombok
Task :sourcesJar
Task :generatePomFileForMavenJavaPublication
Task :generateEffectiveLombokConfig
Task :compileJava
Task :classes
Task :jar

Task :javadoc
12 warnings

Task :javadocJar
Task :generateMetadataFileForMavenJavaPublication
Task :signMavenJavaPublication FAILED
14 actionable tasks: 14 executed

Unfortunately this error doesn't have any additional information. Feel free to kindly ask the author of the @semantic-release/exec plugin to add more helpful information.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • fix(deps): update all non-major dependencies (org.apache.commons:commons-lang3, software.amazon.awssdk:dynamodb-enhanced, software.amazon.awssdk:sts, software.amazon.awssdk:dynamodb, io.freefair.lombok)

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/build.yml
  • actions/checkout v4
  • actions/setup-java v4
  • actions/cache v4
  • codecov/codecov-action v4
.github/workflows/codegen.yml
  • actions/checkout v4
  • actions/setup-java v4
  • actions/cache v4
.github/workflows/semantic-pr.yml
  • amannn/action-semantic-pull-request v5
.github/workflows/spotless.yml
  • actions/checkout v4
  • actions/setup-java v4
  • actions/cache v4
gradle
settings.gradle
build.gradle
  • org.danilopianini.git-sensitive-semantic-versioning-gradle-plugin 3.1.7
  • io.freefair.lombok 8.6
  • io.github.gradle-nexus.publish-plugin 1.3.0
  • com.diffplug.spotless 6.25.0
  • software.amazon.awssdk:dynamodb 2.26.30
  • com.fasterxml.jackson.core:jackson-databind 2.17.2
  • org.junit.jupiter:junit-jupiter-api 5.10.3
  • org.junit.jupiter:junit-jupiter-params 5.10.3
  • org.junit.jupiter:junit-jupiter-engine 5.10.3
  • org.mockito:mockito-core 5.12.0
  • commons-codec:commons-codec 1.17.1
  • software.amazon.awssdk:sts 2.26.30
  • com.amazonaws:aws-java-sdk-sts 1.12.767
  • software.amazon.awssdk:dynamodb-enhanced 2.26.30
  • com.amazonaws:aws-java-sdk-dynamodb 1.12.767
  • org.apache.commons:commons-math3 3.6.1
  • com.autonomouslogic.jacksonobjectstream:jackson-object-stream 0.2.21
  • org.apache.commons:commons-lang3 3.15.0
buildSrc/build.gradle
  • io.freefair.lombok 8.6
  • software.amazon.awssdk:dynamodb 2.26.30
  • com.squareup:javapoet 1.13.0
  • org.apache.commons:commons-lang3 3.15.0
  • org.projectlombok:lombok 1.18.34
  • com.fasterxml.jackson.core:jackson-databind 2.17.2
  • org.junit.jupiter:junit-jupiter-api 5.10.3
  • org.junit.jupiter:junit-jupiter-params 5.10.3
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.9

Add support for BatchWriteItem

BatchWriteItemRequest is able to take a bunch of PutRequest and DeleteRequest inside WriteRequest wrappers. It might make sense to implement helper methods like batch put and batch delete. Unprocessed items in the response will have to be mapped and returned in a sensible way as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.