Skip to content

Commit

Permalink
feat: jackson features支持传入 SerializationFeature DeserializationFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
qw623577789 committed Oct 8, 2022
1 parent 4f31aaa commit 3e59de0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
}
dependencies {
implementation 'com.github.qw623577789:qtk-json:v1.12.0'
implementation 'com.github.qw623577789:qtk-json:v1.13.0'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

group = "team.qtk"
version = "1.12.0"
version = "1.13.0"
sourceCompatibility = 11
targetCompatibility = 11

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/team/qtk/json/JSON.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package team.qtk.json;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.FormatFeature;
import com.fasterxml.jackson.core.PrettyPrinter;
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.core.json.JsonWriteFeature;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
Expand Down Expand Up @@ -734,13 +735,17 @@ public JSONConfig(JsonMapper.Builder customJacksonBuilder) {
this.customJacksonBuilder = customJacksonBuilder;
}

public JSONConfig features(HashMap<FormatFeature, Boolean> features) {
public JSONConfig features(HashMap<Object, Boolean> features) {
features
.forEach((key, value) -> {
if (key instanceof JsonReadFeature) {
customJacksonBuilder.configure((JsonReadFeature) key, value);
} else if (key instanceof JsonWriteFeature) {
customJacksonBuilder.configure((JsonWriteFeature) key, value);
} else if (key instanceof SerializationFeature) {
customJacksonBuilder.configure((SerializationFeature) key, value);
} else if (key instanceof DeserializationFeature) {
customJacksonBuilder.configure((DeserializationFeature) key, value);
} else {
throw new RuntimeException("no support feature:" + ((Object) key).getClass().getName());
}
Expand Down

0 comments on commit 3e59de0

Please sign in to comment.