refactor: json缩进增加为4个空格
This commit is contained in:
parent
ea594c4048
commit
92fd8f3dbd
@ -1,10 +1,15 @@
|
|||||||
package org.jcnc.jnotepad.tool;
|
package org.jcnc.jnotepad.tool;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.PrettyPrinter;
|
||||||
|
import com.fasterxml.jackson.core.util.DefaultIndenter;
|
||||||
|
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import org.jcnc.jnotepad.exception.AppException;
|
import org.jcnc.jnotepad.exception.AppException;
|
||||||
|
|
||||||
|
import static com.fasterxml.jackson.core.util.DefaultIndenter.SYS_LF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* jackson解析器的facade类,主要提供objectMapper对象
|
* jackson解析器的facade类,主要提供objectMapper对象
|
||||||
*
|
*
|
||||||
@ -14,7 +19,16 @@ public class JsonUtil {
|
|||||||
private JsonUtil() {
|
private JsonUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
|
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
|
static {
|
||||||
|
OBJECT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
|
||||||
|
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
|
||||||
|
DefaultIndenter di = new DefaultIndenter(" ", SYS_LF);
|
||||||
|
prettyPrinter.indentArraysWith(di);
|
||||||
|
prettyPrinter.indentObjectsWith(di);
|
||||||
|
OBJECT_MAPPER.setDefaultPrettyPrinter(prettyPrinter);
|
||||||
|
}
|
||||||
|
|
||||||
public static String toJsonString(Object o) {
|
public static String toJsonString(Object o) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user