-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Jackson serializer which can serialize mostly anything (#260)
- Loading branch information
1 parent
bd1c71a
commit 9ec6dc5
Showing
17 changed files
with
1,047 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# transaction-outbox-jackson | ||
|
||
[![Jackson on Maven Central](https://maven-badges.herokuapp.com/maven-central/com.gruelbox/transactionoutbox-jackson/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.gruelbox/transactionoutbox-guice) | ||
[![Jackson Javadoc](https://www.javadoc.io/badge/com.gruelbox/transactionoutbox-jackson.svg?color=blue)](https://www.javadoc.io/doc/com.gruelbox/transactionoutbox-guice) | ||
[![Latest snapshot](https://img.shields.io/github/v/tag/gruelbox/transaction-outbox?label=snapshot&sort=semver)](#development-snapshots) | ||
|
||
Extension for [transaction-outbox-core](../README.md) which uses Jackson for serialisation. | ||
|
||
If you are confident in trusting your database, then this serializer has a number of advantages: it is as | ||
configurable as whatever Jackson's `ObjectMapper` can handle, and explicitly handles n-depth polymorphic trees. This | ||
largely means that you can throw pretty much anything at it and it will "just work". | ||
|
||
However, if there is any risk that you might not trust the source of the serialized `Invocation`, | ||
_do not use this_. This serializer is vulnerable to | ||
[deserialization of untrusted data](https://github.com/gruelbox/transaction-outbox/issues/236#issuecomment-1024929436), | ||
which is why it is not included in the core library. | ||
|
||
## Installation | ||
|
||
### Stable releases | ||
|
||
#### Maven | ||
|
||
```xml | ||
<dependency> | ||
<groupId>com.gruelbox</groupId> | ||
<artifactId>transactionoutbox-jackson</artifactId> | ||
<version>4.2.268</version> | ||
</dependency> | ||
``` | ||
|
||
#### Gradle | ||
|
||
```groovy | ||
implementation 'com.gruelbox:transactionoutbox-jackson:4.2.268' | ||
``` | ||
|
||
### Development snapshots | ||
|
||
See [transactionoutbox-core](../README.md) for more information. | ||
|
||
## Configuration | ||
|
||
### Fresh projects | ||
|
||
If starting with a fresh project, you don't need to worry about compatibility with DefaultInvocationSerializer, so configure as follows: | ||
|
||
```java | ||
var outbox = TransactionOutbox.builder() | ||
.persistor(DefaultPersistor.builder() | ||
.dialect(Dialect.H2) | ||
.serializer(JacksonInvocationSerializer.builder() | ||
.mapper(new ObjectMapper()) | ||
.build()) | ||
.build()) | ||
``` | ||
|
||
### Existing projects using DefaultInvocationSerializer | ||
|
||
If you're already using Transaction Outbox, you may have outbox tasks queued which your application needs to continue to be capable of loading. | ||
To handle this, pass through an instance of `DefaultInvocationSerializer` which matches what you used previously: | ||
|
||
```java | ||
var outbox = TransactionOutbox.builder() | ||
.persistor(DefaultPersistor.builder() | ||
.dialect(Dialect.H2) | ||
.serializer(JacksonInvocationSerializer.builder() | ||
.mapper(new ObjectMapper()) | ||
.defaultInvocationSerializer(DefaultInvocationSerializer.builder() | ||
.serializableTypes(Set.of(Foo.class, Bar.class)) | ||
.build()) | ||
.build()) | ||
.build()) | ||
``` | ||
|
||
## Usage | ||
|
||
You can now go wild with your scheduled method arguments: | ||
|
||
```java | ||
outbox.schedule(getClass()) | ||
.process(List.of(LocalDate.of(2000,1,1), "a", "b", 2)); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>transactionoutbox-parent</artifactId> | ||
<groupId>com.gruelbox</groupId> | ||
<version>${revision}</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<name>Transaction Outbox Jackson</name> | ||
<packaging>jar</packaging> | ||
<artifactId>transactionoutbox-jackson</artifactId> | ||
<description>A safe implementation of the transactional outbox pattern for Java (Jackson extension library) | ||
</description> | ||
|
||
<properties> | ||
<guice.version>5.2.4.RELEASE</guice.version> | ||
<jackson.version>2.13.2</jackson.version> | ||
<commons.lang.version>3.12.0</commons.lang.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<!-- Run time --> | ||
<dependency> | ||
<groupId>com.gruelbox</groupId> | ||
<artifactId>transactionoutbox-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>${jackson.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>${commons.lang.version}</version> | ||
</dependency> | ||
|
||
<!-- Compile time --> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
|
||
<!-- Test --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-guava</artifactId> | ||
<version>${jackson.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jdk8</artifactId> | ||
<version>${jackson.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jsr310</artifactId> | ||
<version>${jackson.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.zaxxer</groupId> | ||
<artifactId>HikariCP</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.