clear jackson method
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.imyeyu.api.modules.common.controller;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.imyeyu.api.bean.CaptchaFrom;
|
||||
@@ -47,8 +48,8 @@ import lombok.Cleanup;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.tika.Tika;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.data.mongodb.gridfs.GridFsResource;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -101,22 +102,6 @@ public class CommonController {
|
||||
private final CaptchaManager captchaManager;
|
||||
private final ResourceHandler resourceHandler;
|
||||
|
||||
private String writeJson(Object value) {
|
||||
try {
|
||||
return jackson.writeValueAsString(value);
|
||||
} catch (IOException e) {
|
||||
throw new TimiException(TimiCode.ERROR, "write json error", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> readJsonMap(String value) {
|
||||
try {
|
||||
return jackson.readValue(value, new TypeReference<>() {});
|
||||
} catch (IOException e) {
|
||||
throw new TimiException(TimiCode.ERROR, "read json error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
@RequestMapping("")
|
||||
public String root() {
|
||||
@@ -256,7 +241,7 @@ public class CommonController {
|
||||
|
||||
@RequestRateLimit
|
||||
@GetMapping("/setting/{key}")
|
||||
public String settingByKey(@PathVariable("key") String key, @RequestParam(value = "as", required = false) Setting.Type asType) {
|
||||
public String settingByKey(@PathVariable("key") String key, @RequestParam(value = "as", required = false) Setting.Type asType) throws JsonProcessingException {
|
||||
Setting setting = settingService.getByKey(SettingKey.valueOf(key.toUpperCase()));
|
||||
if (setting.isPrivate()) {
|
||||
throw new TimiException(TimiCode.PERMISSION_ERROR);
|
||||
@@ -269,12 +254,12 @@ public class CommonController {
|
||||
case JSON -> {
|
||||
if (setting.getType() == Setting.Type.YAML) {
|
||||
Map<String, Object> obj = yaml.load(setting.getValue());
|
||||
result = writeJson(obj);
|
||||
result = jackson.writeValueAsString(obj);
|
||||
}
|
||||
}
|
||||
case YAML -> {
|
||||
if (setting.getType() == Setting.Type.JSON) {
|
||||
Map<String, Object> obj = readJsonMap(setting.getValue());
|
||||
Map<String, Object> obj = jackson.readValue(setting.getValue(), new TypeReference<>() {});
|
||||
result = yaml.dump(obj);
|
||||
}
|
||||
}
|
||||
@@ -284,7 +269,7 @@ public class CommonController {
|
||||
|
||||
@RequestRateLimit
|
||||
@PostMapping("/setting/map")
|
||||
public Map<SettingKey, String> mapSettingByKeys(@RequestBody Map<SettingKey, Map<String, Object>> settingMap) {
|
||||
public Map<SettingKey, String> mapSettingByKeys(@RequestBody Map<SettingKey, Map<String, Object>> settingMap) throws JsonProcessingException {
|
||||
List<Setting> result = settingService.listByKeys(new ArrayList<>(settingMap.keySet()));
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
Setting setting = result.get(i);
|
||||
@@ -300,12 +285,12 @@ public class CommonController {
|
||||
case JSON -> {
|
||||
if (setting.getType() == Setting.Type.YAML) {
|
||||
Map<String, Object> obj = new Yaml().load(setting.getValue());
|
||||
setting.setValue(writeJson(obj));
|
||||
setting.setValue(jackson.writeValueAsString(obj));
|
||||
}
|
||||
}
|
||||
case YAML -> {
|
||||
if (setting.getType() == Setting.Type.JSON) {
|
||||
Map<String, Object> obj = readJsonMap(setting.getValue());
|
||||
Map<String, Object> obj = jackson.readValue(setting.getValue(), new TypeReference<>() {});
|
||||
setting.setValue(new Yaml().dump(obj));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user