Skip to content

Commit 954b8e6

Browse files
committed
Clean up
1 parent 29b6eb9 commit 954b8e6

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

client/java-armeria/src/test/java/com/linecorp/centraldogma/client/armeria/ArmeriaCentralDogmaTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ static List<Arguments> json5Queries() {
130130
}
131131

132132
static class MockEntryDto {
133+
133134
private final String path;
134135
private final String type;
135136
private final String content;
@@ -157,6 +158,7 @@ String content() {
157158
}
158159

159160
static class MockWatchResultDto {
161+
160162
private final int revision;
161163
private final MockEntryDto entry;
162164

common/src/main/java/com/linecorp/centraldogma/internal/Jackson.java

+30-17
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.IOException;
2626
import java.io.Writer;
2727
import java.time.Instant;
28+
import java.util.Arrays;
2829
import java.util.Iterator;
2930
import java.util.Set;
3031

@@ -36,6 +37,7 @@
3637
import com.fasterxml.jackson.core.TreeNode;
3738
import com.fasterxml.jackson.core.io.JsonStringEncoder;
3839
import com.fasterxml.jackson.core.io.SegmentedStringWriter;
40+
import com.fasterxml.jackson.core.json.JsonReadFeature;
3941
import com.fasterxml.jackson.core.type.TypeReference;
4042
import com.fasterxml.jackson.core.util.DefaultIndenter;
4143
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
@@ -75,23 +77,16 @@ public final class Jackson {
7577
compactMapper.disable(SerializationFeature.INDENT_OUTPUT);
7678
prettyMapper.enable(SerializationFeature.INDENT_OUTPUT);
7779
// Sort the attributes when serialized via the mapper.
78-
compactMapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
79-
prettyMapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
80-
81-
compactMapper.enable(Feature.ALLOW_SINGLE_QUOTES);
82-
prettyMapper.enable(Feature.ALLOW_SINGLE_QUOTES);
83-
compactMapper.enable(Feature.ALLOW_UNQUOTED_FIELD_NAMES);
84-
prettyMapper.enable(Feature.ALLOW_UNQUOTED_FIELD_NAMES);
85-
compactMapper.enable(Feature.ALLOW_COMMENTS);
86-
prettyMapper.enable(Feature.ALLOW_COMMENTS);
87-
compactMapper.enable(Feature.ALLOW_TRAILING_COMMA);
88-
prettyMapper.enable(Feature.ALLOW_TRAILING_COMMA);
89-
compactMapper.enable(Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER);
90-
prettyMapper.enable(Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER);
91-
compactMapper.enable(Feature.ALLOW_NON_NUMERIC_NUMBERS);
92-
prettyMapper.enable(Feature.ALLOW_NON_NUMERIC_NUMBERS);
93-
compactMapper.enable(Feature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS);
94-
prettyMapper.enable(Feature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS);
80+
enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
81+
82+
// Enable JSON5 features.
83+
enable(JsonReadFeature.ALLOW_SINGLE_QUOTES,
84+
JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES,
85+
JsonReadFeature.ALLOW_JAVA_COMMENTS,
86+
JsonReadFeature.ALLOW_TRAILING_COMMA,
87+
JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER,
88+
JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS,
89+
JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS);
9590

9691
registerModules(new SimpleModule().addSerializer(Instant.class, InstantSerializer.INSTANCE)
9792
.addDeserializer(Instant.class, InstantDeserializer.INSTANT));
@@ -145,6 +140,24 @@ public static void registerSubtypes(Class<?>... subtypes) {
145140
prettyMapper.registerSubtypes(subtypes);
146141
}
147142

143+
public static void enable(SerializationFeature... features) {
144+
for (SerializationFeature feature : features) {
145+
compactMapper.enable(feature);
146+
prettyMapper.enable(feature);
147+
}
148+
}
149+
150+
public static void enable(JsonReadFeature... features) {
151+
enable(Arrays.stream(features).map(JsonReadFeature::mappedFeature).toArray(Feature[]::new));
152+
}
153+
154+
public static void enable(Feature... features) {
155+
for (Feature feature : features) {
156+
compactMapper.enable(feature);
157+
prettyMapper.enable(feature);
158+
}
159+
}
160+
148161
public static <T> T readValue(String data, Class<T> type) throws JsonParseException, JsonMappingException {
149162
try {
150163
return compactMapper.readValue(data, type);

server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/GitRepository.java

-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,6 @@ private Map<String, Change<?>> toChangeMap(List<DiffEntry> diffEntryList) {
777777
Change.ofJsonPatch(newPath, Jackson.valueToTree(patch)));
778778
}
779779
break;
780-
// TODO(ks.yim): maybe needs Change.ofJson5Patch(...)?
781780
case JSON5:
782781
case TEXT:
783782
final String oldText = sanitizeText(new String(

0 commit comments

Comments
 (0)