Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ks-yim committed Dec 11, 2021
1 parent 29b6eb9 commit 954b8e6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ static List<Arguments> json5Queries() {
}

static class MockEntryDto {

private final String path;
private final String type;
private final String content;
Expand Down Expand Up @@ -157,6 +158,7 @@ String content() {
}

static class MockWatchResultDto {

private final int revision;
private final MockEntryDto entry;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.Writer;
import java.time.Instant;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Set;

Expand All @@ -36,6 +37,7 @@
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.core.io.JsonStringEncoder;
import com.fasterxml.jackson.core.io.SegmentedStringWriter;
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.core.util.DefaultIndenter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
Expand Down Expand Up @@ -75,23 +77,16 @@ public final class Jackson {
compactMapper.disable(SerializationFeature.INDENT_OUTPUT);
prettyMapper.enable(SerializationFeature.INDENT_OUTPUT);
// Sort the attributes when serialized via the mapper.
compactMapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
prettyMapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);

compactMapper.enable(Feature.ALLOW_SINGLE_QUOTES);
prettyMapper.enable(Feature.ALLOW_SINGLE_QUOTES);
compactMapper.enable(Feature.ALLOW_UNQUOTED_FIELD_NAMES);
prettyMapper.enable(Feature.ALLOW_UNQUOTED_FIELD_NAMES);
compactMapper.enable(Feature.ALLOW_COMMENTS);
prettyMapper.enable(Feature.ALLOW_COMMENTS);
compactMapper.enable(Feature.ALLOW_TRAILING_COMMA);
prettyMapper.enable(Feature.ALLOW_TRAILING_COMMA);
compactMapper.enable(Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER);
prettyMapper.enable(Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER);
compactMapper.enable(Feature.ALLOW_NON_NUMERIC_NUMBERS);
prettyMapper.enable(Feature.ALLOW_NON_NUMERIC_NUMBERS);
compactMapper.enable(Feature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS);
prettyMapper.enable(Feature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS);
enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);

// Enable JSON5 features.
enable(JsonReadFeature.ALLOW_SINGLE_QUOTES,
JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES,
JsonReadFeature.ALLOW_JAVA_COMMENTS,
JsonReadFeature.ALLOW_TRAILING_COMMA,
JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER,
JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS,
JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS);

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

public static void enable(SerializationFeature... features) {
for (SerializationFeature feature : features) {
compactMapper.enable(feature);
prettyMapper.enable(feature);
}
}

public static void enable(JsonReadFeature... features) {
enable(Arrays.stream(features).map(JsonReadFeature::mappedFeature).toArray(Feature[]::new));
}

public static void enable(Feature... features) {
for (Feature feature : features) {
compactMapper.enable(feature);
prettyMapper.enable(feature);
}
}

public static <T> T readValue(String data, Class<T> type) throws JsonParseException, JsonMappingException {
try {
return compactMapper.readValue(data, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,6 @@ private Map<String, Change<?>> toChangeMap(List<DiffEntry> diffEntryList) {
Change.ofJsonPatch(newPath, Jackson.valueToTree(patch)));
}
break;
// TODO(ks.yim): maybe needs Change.ofJson5Patch(...)?
case JSON5:
case TEXT:
final String oldText = sanitizeText(new String(
Expand Down

0 comments on commit 954b8e6

Please sign in to comment.