com.gruelbox.transactionoutbox.jackson.TransactionOutboxEntryDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of transactionoutbox-jackson Show documentation
Show all versions of transactionoutbox-jackson Show documentation
A safe implementation of the transactional outbox pattern for Java (Jackson extension library)
package com.gruelbox.transactionoutbox.jackson;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.gruelbox.transactionoutbox.Invocation;
import com.gruelbox.transactionoutbox.TransactionOutboxEntry;
import java.io.IOException;
import java.time.Instant;
import java.util.Map;
class TransactionOutboxEntryDeserializer extends JsonDeserializer {
@Override
public TransactionOutboxEntry deserialize(JsonParser p, DeserializationContext c)
throws IOException {
ObjectCodec oc = p.getCodec();
JsonNode node = oc.readTree(p);
var i = node.get("invocation");
var mdc = i.get("mdc");
return TransactionOutboxEntry.builder()
.id(node.get("id").asText())
.lastAttemptTime(mapJsonInstant(node, "lastAttemptTime", c))
.nextAttemptTime(mapJsonInstant(node, "nextAttemptTime", c))
.attempts(node.get("attempts").asInt())
.blocked(node.get("blocked").asBoolean())
.processed(node.get("processed").asBoolean())
.uniqueRequestId(mapJsonNull(node.get("uniqueRequestId"), JsonNode::asText))
.version(node.get("version").asInt())
.invocation(
new Invocation(
i.get("className").asText(),
i.get("methodName").asText(),
c.readTreeAsValue(i.get("parameterTypes"), Class[].class),
c.readTreeAsValue(i.get("args"), Object[].class),
mdc.isNull()
? null
: c.readTreeAsValue(
mdc,
c.getTypeFactory()
.constructType(new TypeReference