@ThreadSafe public final class Jsons extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static Jsons |
ALL
不排除任何属性
|
static com.fasterxml.jackson.databind.ObjectMapper |
JSON5
Object mapper support json5
|
static com.fasterxml.jackson.core.type.TypeReference<List<String>> |
LIST_STRING |
static com.fasterxml.jackson.core.type.TypeReference<Map<String,Object>> |
MAP_NORMAL |
static Jsons |
NORMAL
标准:忽略对象中值为null的属性
|
| 限定符和类型 | 方法和说明 |
|---|---|
byte[] |
bytes(Object target)
Serialize the byte array of json
|
static void |
configObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
static com.fasterxml.jackson.databind.ObjectMapper |
createObjectMapper(com.fasterxml.jackson.annotation.JsonInclude.Include include)
也可以使用JsonMapper.Builder来构建:
ObjectMapper objectMapper = JsonMapper.builder()
.serializationInclusion(JsonInclude.Include.NON_NULL) // 序列化时忽略值为null的字段
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) // 反序列化时忽略未知字段
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES) // 键和值:可以用单引号
.enable(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER) // 字符串值:可以通过转义换行符来跨越多行
.enable(JsonReadFeature.ALLOW_TRAILING_COMMA) // 对象或数组:可以有一个尾随逗号
.enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS) // 允许有未转义的控制符
.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS) // 允许单行和多行注释
.build();
|
static <T> T |
fromJson(byte[] json,
Class<T> target) |
static <T> T |
fromJson(byte[] json,
com.fasterxml.jackson.databind.JavaType javaType) |
static <T> T |
fromJson(byte[] json,
Type target) |
static <T> T |
fromJson(byte[] json,
com.fasterxml.jackson.core.type.TypeReference<T> type) |
static <T> T |
fromJson(String json,
Class<T> target) |
static <T> T |
fromJson(String json,
com.fasterxml.jackson.databind.JavaType javaType) |
static <T> T |
fromJson(String json,
Type target) |
static <T> T |
fromJson(String json,
com.fasterxml.jackson.core.type.TypeReference<T> type) |
<T> T |
parse(byte[] json,
Class<T> target) |
<T> T |
parse(byte[] json,
com.fasterxml.jackson.databind.JavaType javaType)
Deserialize the json byte array to java object
|
<T> T |
parse(byte[] json,
Type type) |
<T> T |
parse(byte[] json,
com.fasterxml.jackson.core.type.TypeReference<T> type) |
<T> T |
parse(String json,
Class<T> target) |
<T> T |
parse(String json,
com.fasterxml.jackson.databind.JavaType javaType)
Deserialize the json string to java object
|
<T> T |
parse(String json,
Type type) |
<T> T |
parse(String json,
com.fasterxml.jackson.core.type.TypeReference<T> type) |
static Object[] |
parseArgs(String body,
Type[] parameterTypes) |
static Object[] |
parseArray(String body,
Class<?>... types) |
static Object[] |
parseMethodArgs(String body,
Method method) |
static void |
registerJavaTimeModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
static void |
registerSimpleModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
String |
string(Object target)
Converts an object(POJO, Array, Collection, ...) to json string
|
static byte[] |
toBytes(Object target) |
static String |
toJson(Object target) |
void |
write(OutputStream output,
Object target)
Converts object to json, and write to output stream
|
public static final com.fasterxml.jackson.core.type.TypeReference<Map<String,Object>> MAP_NORMAL
public static final com.fasterxml.jackson.core.type.TypeReference<List<String>> LIST_STRING
public static final Jsons NORMAL
public static final Jsons ALL
public static final com.fasterxml.jackson.databind.ObjectMapper JSON5
public void write(OutputStream output, Object target)
output - the output streamtarget - the target objectpublic String string(Object target)
target - target objectpublic byte[] bytes(Object target)
target - objectpublic <T> T parse(String json, com.fasterxml.jackson.databind.JavaType javaType)
json - json stringjavaType - JavaTypeObjectMapper.getTypeFactory(),
ObjectMapper.constructType(Type),
TypeFactory.constructGeneralizedType(JavaType, Class)public <T> T parse(byte[] json,
com.fasterxml.jackson.databind.JavaType javaType)
json - json byte arrayjavaType - JavaTypepublic <T> T parse(byte[] json,
Class<T> target)
public <T> T parse(byte[] json,
Type type)
public <T> T parse(String json, com.fasterxml.jackson.core.type.TypeReference<T> type)
public <T> T parse(byte[] json,
com.fasterxml.jackson.core.type.TypeReference<T> type)
public static byte[] toBytes(Object target)
public static <T> T fromJson(String json, com.fasterxml.jackson.databind.JavaType javaType)
public static <T> T fromJson(byte[] json,
com.fasterxml.jackson.databind.JavaType javaType)
public static <T> T fromJson(byte[] json,
Class<T> target)
public static <T> T fromJson(byte[] json,
Type target)
public static <T> T fromJson(String json, com.fasterxml.jackson.core.type.TypeReference<T> type)
public static <T> T fromJson(byte[] json,
com.fasterxml.jackson.core.type.TypeReference<T> type)
public static com.fasterxml.jackson.databind.ObjectMapper createObjectMapper(com.fasterxml.jackson.annotation.JsonInclude.Include include)
也可以使用JsonMapper.Builder来构建:
ObjectMapper objectMapper = JsonMapper.builder()
.serializationInclusion(JsonInclude.Include.NON_NULL) // 序列化时忽略值为null的字段
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) // 反序列化时忽略未知字段
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES) // 键和值:可以用单引号
.enable(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER) // 字符串值:可以通过转义换行符来跨越多行
.enable(JsonReadFeature.ALLOW_TRAILING_COMMA) // 对象或数组:可以有一个尾随逗号
.enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS) // 允许有未转义的控制符
.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS) // 允许单行和多行注释
.build();
include - the JsonIncludepublic static void configObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
public static void registerSimpleModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
public static void registerJavaTimeModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Copyright © 2025. All rights reserved.