diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java b/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java index 65efbf3b5a9..9565a1e9904 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java @@ -16,7 +16,11 @@ package org.openrewrite.marker; -import lombok.*; +import com.fasterxml.jackson.annotation.JsonCreator; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Value; +import lombok.With; import lombok.experimental.NonFinal; import org.openrewrite.GitRemote; import org.openrewrite.Incubating; @@ -44,7 +48,6 @@ @Value @AllArgsConstructor(access = AccessLevel.PACKAGE) // required for @With and tests -@RequiredArgsConstructor @With public class GitProvenance implements Marker { UUID id; @@ -77,6 +80,24 @@ public class GitProvenance implements Marker { @Nullable GitRemote gitRemote; + // javadoc does not like @RequiredArgsConstructor(onConstructor_ = { @JsonCreator }) + @JsonCreator + public GitProvenance(UUID id, + @Nullable String origin, + @Nullable String branch, + @Nullable String change, + @Nullable AutoCRLF autocrlf, + @Nullable EOL eol, + @Nullable List committers) { + this.id = id; + this.origin = origin; + this.branch = branch; + this.change = change; + this.autocrlf = autocrlf; + this.eol = eol; + this.committers = committers; + } + public @Nullable GitRemote getGitRemote() { if (gitRemote == null && origin != null) { gitRemote = new GitRemote.Parser().parse(origin); diff --git a/rewrite-core/src/test/java/org/openrewrite/marker/GitProvenanceTest.java b/rewrite-core/src/test/java/org/openrewrite/marker/GitProvenanceTest.java index 5a2345e3692..d216a718475 100644 --- a/rewrite-core/src/test/java/org/openrewrite/marker/GitProvenanceTest.java +++ b/rewrite-core/src/test/java/org/openrewrite/marker/GitProvenanceTest.java @@ -15,6 +15,9 @@ */ package org.openrewrite.marker; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -45,6 +48,8 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Stream; +import static com.fasterxml.jackson.core.JsonParser.Feature.IGNORE_UNDEFINED; +import static com.fasterxml.jackson.core.JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION; import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assumptions.assumeTrue; @@ -396,6 +401,18 @@ void supportsTravis(@TempDir Path projectDir) throws Exception { } } + @Test + void serialization() throws JsonProcessingException { + GitProvenance gitProvenance = new GitProvenance(randomId(), "https://github.com/octocat/Hello-World.git", "main", "123", null, null, List.of()); + ObjectMapper mapper = new ObjectMapper() + .findAndRegisterModules() + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .enable(INCLUDE_SOURCE_IN_LOCATION); + String json = mapper.writeValueAsString(gitProvenance); + GitProvenance read = mapper.readValue(json, GitProvenance.class); + assertThat(read).isEqualTo(gitProvenance); + } + void runCommand(Path workingDir, String command) { //noinspection ResultOfMethodCallIgnored workingDir.toFile().mkdirs();