diff --git a/common/src/main/java/com/linecorp/centraldogma/common/Change.java b/common/src/main/java/com/linecorp/centraldogma/common/Change.java index 213063aff2..34c2f96a13 100644 --- a/common/src/main/java/com/linecorp/centraldogma/common/Change.java +++ b/common/src/main/java/com/linecorp/centraldogma/common/Change.java @@ -84,7 +84,7 @@ static Change ofTextUpsert(String path, byte[] content) { static Change ofTextUpsert(String path, String text) { requireNonNull(text, "text"); validateFilePath(path, "path"); - if (EntryType.guessFromPath(path) == EntryType.JSON) { + if (EntryType.guessFromPath(path) == EntryType.JSON && !isJson5(path)) { throw new ChangeFormatException("invalid file type: " + path + " (expected: a non-JSON file). Use Change.ofJsonUpsert() instead"); } diff --git a/it/src/test/java/com/linecorp/centraldogma/it/TestConstants.java b/it/src/test/java/com/linecorp/centraldogma/it/TestConstants.java index 8630f19482..100138ab4d 100644 --- a/it/src/test/java/com/linecorp/centraldogma/it/TestConstants.java +++ b/it/src/test/java/com/linecorp/centraldogma/it/TestConstants.java @@ -19,8 +19,6 @@ import static java.util.Objects.requireNonNull; import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; diff --git a/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/GitRepository.java b/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/GitRepository.java index 8cae0c4279..d970d6aaae 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/GitRepository.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/GitRepository.java @@ -754,7 +754,7 @@ private Map> toChangeMap(List diffEntryList) { switch (diffEntry.getChangeType()) { case MODIFY: // Resolve JSON5 as EntryType.TEXT to modify it with text patch because - // json patch can hardly be applied to JSON5. + // applying json patch to JSON5 file makes it a plain JSON. final EntryType oldEntryType = !isJson5(oldPath) ? EntryType.guessFromPath(oldPath) : EntryType.TEXT; switch (oldEntryType) { @@ -798,7 +798,10 @@ private Map> toChangeMap(List diffEntryList) { } break; case ADD: - final EntryType newEntryType = EntryType.guessFromPath(newPath); + // Resolve JSON5 as EntryType.TEXT so that the JSON5 content can properly be included + // in the serialized ReplicationLog. + final EntryType newEntryType = !isJson5(newPath) ? EntryType.guessFromPath(newPath) + : EntryType.TEXT; switch (newEntryType) { case JSON: { final String jsonText = new String(