All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.nichetoolkit.rest.helper.JsonHelper Maven / Gradle / Ivy

The newest version!
package io.github.nichetoolkit.rest.helper;


import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.ArrayType;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import io.github.nichetoolkit.rest.RestResult;
import io.github.nichetoolkit.rest.error.ClassUnsupportedException;
import io.github.nichetoolkit.rest.error.json.JsonParseBeanException;
import io.github.nichetoolkit.rest.error.json.JsonParseListException;
import io.github.nichetoolkit.rest.error.json.JsonParseMapException;
import io.github.nichetoolkit.rest.error.json.JsonParseSetException;
import io.github.nichetoolkit.rest.error.supply.JsonParseException;
import io.github.nichetoolkit.rest.holder.ObjectMapperHolder;
import io.github.nichetoolkit.rest.util.GeneralUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * JsonHelper
 * 

The json helper class.

* @author Cyan ([email protected]) * @see lombok.extern.slf4j.Slf4j * @since Jdk1.8 */ @Slf4j public class JsonHelper { /** * parseJson *

The parse json method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param target T

The target parameter is T type.

* @return {@link java.lang.String}

The parse json return object is String type.

* @throws JsonParseException {@link io.github.nichetoolkit.rest.error.supply.JsonParseException}

The json parse exception is JsonParseException type.

* @see java.lang.String * @see io.github.nichetoolkit.rest.error.supply.JsonParseException */ public static String parseJson(T target) throws JsonParseException { if (GeneralUtils.isEmpty(target)) { return null; } try { return ObjectMapperHolder.objectMapper().writeValueAsString(target); } catch (JsonProcessingException exception) { throw new JsonParseException("parseJson", target.getClass().getName(), exception.getMessage()); } } /** * parseJson *

The parse json method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param target T

The target parameter is T type.

* @param typeReference {@link com.fasterxml.jackson.core.type.TypeReference}

The type reference parameter is TypeReference type.

* @return {@link java.lang.String}

The parse json return object is String type.

* @throws JsonParseException {@link io.github.nichetoolkit.rest.error.supply.JsonParseException}

The json parse exception is JsonParseException type.

* @see com.fasterxml.jackson.core.type.TypeReference * @see java.lang.String * @see io.github.nichetoolkit.rest.error.supply.JsonParseException */ public static String parseJson(T target, TypeReference typeReference) throws JsonParseException { if (GeneralUtils.isEmpty(target)) { return null; } try { return ObjectMapperHolder.objectMapper().writerFor(typeReference).writeValueAsString(target); } catch (JsonProcessingException exception) { throw new JsonParseException("parseJson", target.getClass().getName(), exception.getMessage()); } } /** * parseJsonIgnoreNull *

The parse json ignore null method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param target T

The target parameter is T type.

* @return {@link java.lang.String}

The parse json ignore null return object is String type.

* @throws JsonParseException {@link io.github.nichetoolkit.rest.error.supply.JsonParseException}

The json parse exception is JsonParseException type.

* @see java.lang.String * @see io.github.nichetoolkit.rest.error.supply.JsonParseException */ public static String parseJsonIgnoreNull(T target) throws JsonParseException { if (GeneralUtils.isEmpty(target)) { return null; } try { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper.writeValueAsString(target); } catch (JsonProcessingException exception) { throw new JsonParseException("parseJsonIgnoreNull", target.getClass().getName(), exception.getMessage()); } } /** * parseBean *

The parse bean method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param clazz {@link java.lang.Class}

The clazz parameter is Class type.

* @return T

The parse bean return object is T type.

* @throws JsonParseBeanException {@link io.github.nichetoolkit.rest.error.json.JsonParseBeanException}

The json parse bean exception is JsonParseBeanException type.

* @see java.lang.String * @see java.lang.Class * @see io.github.nichetoolkit.rest.error.json.JsonParseBeanException */ public static T parseBean(String json, Class clazz) throws JsonParseBeanException { if (GeneralUtils.isEmpty(json)) { return null; } try { return ObjectMapperHolder.objectMapper().readValue(json, clazz); } catch (JsonProcessingException exception) { throw new JsonParseBeanException("parseBean", clazz.getName(), json, exception.getMessage()); } } /** * parseBean *

The parse bean method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param typeReference {@link com.fasterxml.jackson.core.type.TypeReference}

The type reference parameter is TypeReference type.

* @return T

The parse bean return object is T type.

* @throws JsonParseBeanException {@link io.github.nichetoolkit.rest.error.json.JsonParseBeanException}

The json parse bean exception is JsonParseBeanException type.

* @see java.lang.String * @see com.fasterxml.jackson.core.type.TypeReference * @see io.github.nichetoolkit.rest.error.json.JsonParseBeanException */ public static T parseBean(String json, TypeReference typeReference) throws JsonParseBeanException { if (GeneralUtils.isEmpty(json)) { return null; } try { return ObjectMapperHolder.objectMapper().readValue(json, typeReference); } catch (JsonProcessingException exception) { throw new JsonParseBeanException("parseBean", typeReference.getType().getTypeName(), json, exception.getMessage()); } } /** * parseBean *

The parse bean method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param javaType {@link com.fasterxml.jackson.databind.JavaType}

The java type parameter is JavaType type.

* @return T

The parse bean return object is T type.

* @throws JsonParseBeanException {@link io.github.nichetoolkit.rest.error.json.JsonParseBeanException}

The json parse bean exception is JsonParseBeanException type.

* @see java.lang.String * @see com.fasterxml.jackson.databind.JavaType * @see io.github.nichetoolkit.rest.error.json.JsonParseBeanException */ public static T parseBean(String json, JavaType javaType) throws JsonParseBeanException { if (GeneralUtils.isEmpty(json)) { return null; } try { return ObjectMapperHolder.objectMapper().readValue(json, javaType); } catch (JsonProcessingException exception) { throw new JsonParseBeanException("parseBean", javaType.getRawClass().getName(), json, exception.getMessage()); } } /** * parseBean *

The parse bean method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param clazz {@link java.lang.Class}

The clazz parameter is Class type.

* @param innerClazz {@link java.lang.Class}

The inner clazz parameter is Class type.

* @return T

The parse bean return object is T type.

* @throws JsonParseBeanException {@link io.github.nichetoolkit.rest.error.json.JsonParseBeanException}

The json parse bean exception is JsonParseBeanException type.

* @see java.lang.String * @see java.lang.Class * @see io.github.nichetoolkit.rest.error.json.JsonParseBeanException */ public static T parseBean(String json, Class clazz, Class innerClazz) throws JsonParseBeanException { if (GeneralUtils.isEmpty(json)) { return null; } JavaType javaType = TypeFactory.defaultInstance().constructParametricType(clazz, innerClazz); try { return ObjectMapperHolder.objectMapper().readValue(json, javaType); } catch (JsonProcessingException exception) { throw new JsonParseBeanException("parseBean", javaType.getRawClass().getName(), json, exception.getMessage()); } } /** * parseArray *

The parse array method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param arrayType {@link com.fasterxml.jackson.databind.type.ArrayType}

The array type parameter is ArrayType type.

* @return T

The parse array return object is T type.

* @throws JsonParseListException {@link io.github.nichetoolkit.rest.error.json.JsonParseListException}

The json parse list exception is JsonParseListException type.

* @see java.lang.String * @see com.fasterxml.jackson.databind.type.ArrayType * @see io.github.nichetoolkit.rest.error.json.JsonParseListException */ public static T[] parseArray(String json, ArrayType arrayType) throws JsonParseListException { if (GeneralUtils.isEmpty(json)) { return null; } try { return ObjectMapperHolder.objectMapper().readValue(json, arrayType); } catch (JsonProcessingException exception) { throw new JsonParseListException("parseArray", arrayType.getRawClass().getName(), json, exception.getMessage()); } } /** * parseArray *

The parse array method.

* @param {@link java.util.List}

The generic parameter is List type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param clazz {@link java.lang.Class}

The clazz parameter is Class type.

* @return T

The parse array return object is T type.

* @throws JsonParseListException {@link io.github.nichetoolkit.rest.error.json.JsonParseListException}

The json parse list exception is JsonParseListException type.

* @see java.util.List * @see java.lang.String * @see java.lang.Class * @see io.github.nichetoolkit.rest.error.json.JsonParseListException */ public static , T> T[] parseArray(String json, Class clazz) throws JsonParseListException { ArrayType arrayType = TypeFactory.defaultInstance().constructArrayType(clazz); return parseArray(json, arrayType); } /** * parseArray *

The parse array method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param typeReference {@link com.fasterxml.jackson.core.type.TypeReference}

The type reference parameter is TypeReference type.

* @return T

The parse array return object is T type.

* @throws JsonParseListException {@link io.github.nichetoolkit.rest.error.json.JsonParseListException}

The json parse list exception is JsonParseListException type.

* @see java.lang.String * @see com.fasterxml.jackson.core.type.TypeReference * @see io.github.nichetoolkit.rest.error.json.JsonParseListException */ public static T[] parseArray(String json, TypeReference typeReference) throws JsonParseListException { ArrayType arrayType = TypeFactory.defaultInstance().constructArrayType(TypeFactory.defaultInstance().constructType(typeReference)); return parseArray(json, arrayType); } /** * parseList *

The parse list method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param listType {@link com.fasterxml.jackson.databind.type.CollectionType}

The list type parameter is CollectionType type.

* @return {@link java.util.List}

The parse list return object is List type.

* @throws JsonParseListException {@link io.github.nichetoolkit.rest.error.json.JsonParseListException}

The json parse list exception is JsonParseListException type.

* @see java.lang.String * @see com.fasterxml.jackson.databind.type.CollectionType * @see java.util.List * @see io.github.nichetoolkit.rest.error.json.JsonParseListException */ public static List parseList(String json, CollectionType listType) throws JsonParseListException { if (GeneralUtils.isEmpty(json)) { return Collections.emptyList(); } try { return ObjectMapperHolder.objectMapper().readValue(json, listType); } catch (JsonProcessingException exception) { throw new JsonParseListException("parseList", listType.getRawClass().getName(),json, exception.getMessage()); } } /** * parseList *

The parse list method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param typeReference {@link com.fasterxml.jackson.core.type.TypeReference}

The type reference parameter is TypeReference type.

* @return {@link java.util.List}

The parse list return object is List type.

* @throws JsonParseListException {@link io.github.nichetoolkit.rest.error.json.JsonParseListException}

The json parse list exception is JsonParseListException type.

* @see java.lang.String * @see com.fasterxml.jackson.core.type.TypeReference * @see java.util.List * @see io.github.nichetoolkit.rest.error.json.JsonParseListException */ public static List parseList(String json, TypeReference> typeReference) throws JsonParseListException { if (GeneralUtils.isEmpty(json)) { return Collections.emptyList(); } try { return ObjectMapperHolder.objectMapper().readValue(json, typeReference); } catch (JsonProcessingException exception) { throw new JsonParseListException("parseList", typeReference.getType().getTypeName(), json, exception.getMessage()); } } /** * parseList *

The parse list method.

* @param {@link java.util.List}

The generic parameter is List type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param parseClazz {@link java.lang.Class}

The parse clazz parameter is Class type.

* @param clazz {@link java.lang.Class}

The clazz parameter is Class type.

* @return {@link java.util.List}

The parse list return object is List type.

* @throws JsonParseListException {@link io.github.nichetoolkit.rest.error.json.JsonParseListException}

The json parse list exception is JsonParseListException type.

* @see java.util.List * @see java.lang.String * @see java.lang.Class * @see io.github.nichetoolkit.rest.error.json.JsonParseListException */ public static , T> List parseList(String json, Class parseClazz, Class clazz) throws JsonParseListException { CollectionType listType = TypeFactory.defaultInstance().constructCollectionType(parseClazz, clazz); return parseList(json, listType); } /** * parseList *

The parse list method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param clazz {@link java.lang.Class}

The clazz parameter is Class type.

* @return {@link java.util.List}

The parse list return object is List type.

* @throws JsonParseListException {@link io.github.nichetoolkit.rest.error.json.JsonParseListException}

The json parse list exception is JsonParseListException type.

* @see java.lang.String * @see java.lang.Class * @see java.util.List * @see io.github.nichetoolkit.rest.error.json.JsonParseListException */ public static List parseList(String json, Class clazz) throws JsonParseListException { return parseList(json, List.class, clazz); } /** * parseSet *

The parse set method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param setType {@link com.fasterxml.jackson.databind.type.CollectionType}

The set type parameter is CollectionType type.

* @return {@link java.util.Set}

The parse set return object is Set type.

* @throws JsonParseSetException {@link io.github.nichetoolkit.rest.error.json.JsonParseSetException}

The json parse set exception is JsonParseSetException type.

* @see java.lang.String * @see com.fasterxml.jackson.databind.type.CollectionType * @see java.util.Set * @see io.github.nichetoolkit.rest.error.json.JsonParseSetException */ public static Set parseSet(String json, CollectionType setType) throws JsonParseSetException { if (GeneralUtils.isEmpty(json)) { return Collections.emptySet(); } try { return ObjectMapperHolder.objectMapper().readValue(json, setType); } catch (JsonProcessingException exception) { throw new JsonParseSetException("parseSet",setType.getRawClass().getName(),json, exception.getMessage()); } } /** * parseSet *

The parse set method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param typeReference {@link com.fasterxml.jackson.core.type.TypeReference}

The type reference parameter is TypeReference type.

* @return {@link java.util.Set}

The parse set return object is Set type.

* @throws JsonParseSetException {@link io.github.nichetoolkit.rest.error.json.JsonParseSetException}

The json parse set exception is JsonParseSetException type.

* @see java.lang.String * @see com.fasterxml.jackson.core.type.TypeReference * @see java.util.Set * @see io.github.nichetoolkit.rest.error.json.JsonParseSetException */ public static Set parseSet(String json, TypeReference> typeReference) throws JsonParseSetException { if (GeneralUtils.isEmpty(json)) { return Collections.emptySet(); } try { return ObjectMapperHolder.objectMapper().readValue(json, typeReference); } catch (JsonProcessingException exception) { throw new JsonParseSetException("parseSet",typeReference.getType().getTypeName(),json, exception.getMessage()); } } /** * parseSet *

The parse set method.

* @param {@link java.util.Set}

The generic parameter is Set type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param parseClazz {@link java.lang.Class}

The parse clazz parameter is Class type.

* @param clazz {@link java.lang.Class}

The clazz parameter is Class type.

* @return {@link java.util.Set}

The parse set return object is Set type.

* @throws JsonParseSetException {@link io.github.nichetoolkit.rest.error.json.JsonParseSetException}

The json parse set exception is JsonParseSetException type.

* @see java.util.Set * @see java.lang.String * @see java.lang.Class * @see io.github.nichetoolkit.rest.error.json.JsonParseSetException */ public static , T> Set parseSet(String json, Class parseClazz, Class clazz) throws JsonParseSetException { CollectionType setType = TypeFactory.defaultInstance().constructCollectionType(parseClazz, clazz); return parseSet(json, setType); } /** * parseSet *

The parse set method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param clazz {@link java.lang.Class}

The clazz parameter is Class type.

* @return {@link java.util.Set}

The parse set return object is Set type.

* @throws JsonParseSetException {@link io.github.nichetoolkit.rest.error.json.JsonParseSetException}

The json parse set exception is JsonParseSetException type.

* @see java.lang.String * @see java.lang.Class * @see java.util.Set * @see io.github.nichetoolkit.rest.error.json.JsonParseSetException */ public static Set parseSet(String json, Class clazz) throws JsonParseSetException { return parseSet(json, Set.class, clazz); } /** * parseMap *

The parse map method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param mapType {@link com.fasterxml.jackson.databind.type.MapType}

The map type parameter is MapType type.

* @return {@link java.util.Map}

The parse map return object is Map type.

* @throws JsonParseMapException {@link io.github.nichetoolkit.rest.error.json.JsonParseMapException}

The json parse map exception is JsonParseMapException type.

* @see java.lang.String * @see com.fasterxml.jackson.databind.type.MapType * @see java.util.Map * @see io.github.nichetoolkit.rest.error.json.JsonParseMapException */ public static Map parseMap(String json, MapType mapType) throws JsonParseMapException { if (GeneralUtils.isEmpty(json)) { return Collections.emptyMap(); } try { return ObjectMapperHolder.objectMapper().readValue(json, mapType); } catch (JsonProcessingException exception) { throw new JsonParseMapException("parseMap", mapType.getRawClass().getName(),json, exception.getMessage()); } } /** * parseMap *

The parse map method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param typeReference {@link com.fasterxml.jackson.core.type.TypeReference}

The type reference parameter is TypeReference type.

* @return {@link java.util.Map}

The parse map return object is Map type.

* @throws JsonParseMapException {@link io.github.nichetoolkit.rest.error.json.JsonParseMapException}

The json parse map exception is JsonParseMapException type.

* @see java.lang.String * @see com.fasterxml.jackson.core.type.TypeReference * @see java.util.Map * @see io.github.nichetoolkit.rest.error.json.JsonParseMapException */ public static Map parseMap(String json, TypeReference> typeReference) throws JsonParseMapException { if (GeneralUtils.isEmpty(json)) { return Collections.emptyMap(); } try { return ObjectMapperHolder.objectMapper().readValue(json, typeReference); } catch (JsonProcessingException exception) { throw new JsonParseMapException("parseMap", typeReference.getType().getTypeName(),json, exception.getMessage()); } } /** * parseMap *

The parse map method.

* @param {@link java.util.Map}

The generic parameter is Map type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param parseClazz {@link java.lang.Class}

The parse clazz parameter is Class type.

* @param keyClazz {@link java.lang.Class}

The key clazz parameter is Class type.

* @param valueClazz {@link java.lang.Class}

The value clazz parameter is Class type.

* @return {@link java.util.Map}

The parse map return object is Map type.

* @throws JsonParseMapException {@link io.github.nichetoolkit.rest.error.json.JsonParseMapException}

The json parse map exception is JsonParseMapException type.

* @see java.util.Map * @see java.lang.String * @see java.lang.Class * @see io.github.nichetoolkit.rest.error.json.JsonParseMapException */ public static , T, K> Map parseMap(String json, Class parseClazz, Class keyClazz, Class valueClazz) throws JsonParseMapException { MapType mapType = TypeFactory.defaultInstance().constructMapType(parseClazz, keyClazz, valueClazz); return parseMap(json, mapType); } /** * parseMap *

The parse map method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param keyClazz {@link java.lang.Class}

The key clazz parameter is Class type.

* @param valueClazz {@link java.lang.Class}

The value clazz parameter is Class type.

* @return {@link java.util.Map}

The parse map return object is Map type.

* @throws JsonParseMapException {@link io.github.nichetoolkit.rest.error.json.JsonParseMapException}

The json parse map exception is JsonParseMapException type.

* @see java.lang.String * @see java.lang.Class * @see java.util.Map * @see io.github.nichetoolkit.rest.error.json.JsonParseMapException */ public static Map parseMap(String json, Class keyClazz, Class valueClazz) throws JsonParseMapException { return parseMap(json, Map.class, keyClazz, valueClazz); } /** * parseMapList *

The parse map list method.

* @param {@link java.util.List}

The generic parameter is List type.

* @param {@link java.util.Map}

The generic parameter is Map type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param parseListClazz {@link java.lang.Class}

The parse list clazz parameter is Class type.

* @param parseMapClazz {@link java.lang.Class}

The parse map clazz parameter is Class type.

* @param keyClazz {@link java.lang.Class}

The key clazz parameter is Class type.

* @param valueClazz {@link java.lang.Class}

The value clazz parameter is Class type.

* @return {@link java.util.Map}

The parse map list return object is Map type.

* @throws JsonParseMapException {@link io.github.nichetoolkit.rest.error.json.JsonParseMapException}

The json parse map exception is JsonParseMapException type.

* @see java.util.List * @see java.util.Map * @see java.lang.String * @see java.lang.Class * @see io.github.nichetoolkit.rest.error.json.JsonParseMapException */ public static , Y extends Map, T, K> Map> parseMapList(String json, Class parseListClazz, Class parseMapClazz, Class keyClazz, Class valueClazz) throws JsonParseMapException { CollectionType collectionType = TypeFactory.defaultInstance().constructCollectionType(parseListClazz, valueClazz); MapType mapType = TypeFactory.defaultInstance().constructMapType(parseMapClazz, keyClazz, collectionType.getRawClass()); return parseMap(json, mapType); } /** * parseListMap *

The parse list map method.

* @param {@link java.util.List}

The generic parameter is List type.

* @param {@link java.util.Map}

The generic parameter is Map type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param wrapKeyClazz {@link java.lang.Class}

The wrap key clazz parameter is Class type.

* @param contentMapClazz {@link java.lang.Class}

The content map clazz parameter is Class type.

* @param contentKeyClazz {@link java.lang.Class}

The content key clazz parameter is Class type.

* @param contentValueClazz {@link java.lang.Class}

The content value clazz parameter is Class type.

* @return {@link java.util.List}

The parse list map return object is List type.

* @throws JsonParseListException {@link io.github.nichetoolkit.rest.error.json.JsonParseListException}

The json parse list exception is JsonParseListException type.

* @see java.util.List * @see java.util.Map * @see java.lang.String * @see java.lang.Class * @see io.github.nichetoolkit.rest.error.json.JsonParseListException */ public static , Y extends Map, T, K> List> parseListMap(String json, Class wrapKeyClazz, Class contentMapClazz, Class contentKeyClazz, Class contentValueClazz) throws JsonParseListException { MapType contentType = TypeFactory.defaultInstance().constructMapType(contentMapClazz, contentKeyClazz, contentValueClazz); CollectionType collectionType = TypeFactory.defaultInstance().constructCollectionType(wrapKeyClazz, contentType.getRawClass()); return parseList(json, collectionType); } /** * parseListMap *

The parse list map method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param contentKeyClazz {@link java.lang.Class}

The content key clazz parameter is Class type.

* @param contentValueClazz {@link java.lang.Class}

The content value clazz parameter is Class type.

* @return {@link java.util.List}

The parse list map return object is List type.

* @throws JsonParseListException {@link io.github.nichetoolkit.rest.error.json.JsonParseListException}

The json parse list exception is JsonParseListException type.

* @see java.lang.String * @see java.lang.Class * @see java.util.List * @see io.github.nichetoolkit.rest.error.json.JsonParseListException */ public static List> parseListMap(String json, Class contentKeyClazz, Class contentValueClazz) throws JsonParseListException { MapType contentType = TypeFactory.defaultInstance().constructMapType(Map.class, contentKeyClazz, contentValueClazz); CollectionType collectionType = TypeFactory.defaultInstance().constructCollectionType(List.class, contentType.getRawClass()); return parseList(json, collectionType); } /** * parseMapList *

The parse map list method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param keyClazz {@link java.lang.Class}

The key clazz parameter is Class type.

* @param valueClazz {@link java.lang.Class}

The value clazz parameter is Class type.

* @return {@link java.util.Map}

The parse map list return object is Map type.

* @throws JsonParseMapException {@link io.github.nichetoolkit.rest.error.json.JsonParseMapException}

The json parse map exception is JsonParseMapException type.

* @see java.lang.String * @see java.lang.Class * @see java.util.Map * @see io.github.nichetoolkit.rest.error.json.JsonParseMapException */ public static Map> parseMapList(String json, Class keyClazz, Class valueClazz) throws JsonParseMapException { return parseMapList(json, List.class, Map.class, keyClazz, valueClazz); } /** * parseMapMap *

The parse map map method.

* @param {@link java.util.Map}

The generic parameter is Map type.

* @param {@link java.util.Map}

The generic parameter is Map type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param wrapMapClazz {@link java.lang.Class}

The wrap map clazz parameter is Class type.

* @param contentMapClazz {@link java.lang.Class}

The content map clazz parameter is Class type.

* @param wrapKeyClazz {@link java.lang.Class}

The wrap key clazz parameter is Class type.

* @param contentKeyClazz {@link java.lang.Class}

The content key clazz parameter is Class type.

* @param contentValueClazz {@link java.lang.Class}

The content value clazz parameter is Class type.

* @return {@link java.util.Map}

The parse map map return object is Map type.

* @throws JsonParseMapException {@link io.github.nichetoolkit.rest.error.json.JsonParseMapException}

The json parse map exception is JsonParseMapException type.

* @see java.util.Map * @see java.lang.String * @see java.lang.Class * @see io.github.nichetoolkit.rest.error.json.JsonParseMapException */ public static , Y extends Map, Z, T, K> Map> parseMapMap(String json, Class wrapMapClazz, Class contentMapClazz, Class wrapKeyClazz, Class contentKeyClazz, Class contentValueClazz) throws JsonParseMapException { MapType contentType = TypeFactory.defaultInstance().constructMapType(contentMapClazz, contentKeyClazz, contentValueClazz); MapType mapType = TypeFactory.defaultInstance().constructMapType(wrapMapClazz, wrapKeyClazz, contentType.getRawClass()); return parseMap(json, mapType); } /** * parseMapMap *

The parse map map method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param wrapKeyClazz {@link java.lang.Class}

The wrap key clazz parameter is Class type.

* @param contentKeyClazz {@link java.lang.Class}

The content key clazz parameter is Class type.

* @param contentValueClazz {@link java.lang.Class}

The content value clazz parameter is Class type.

* @return {@link java.util.Map}

The parse map map return object is Map type.

* @throws JsonParseMapException {@link io.github.nichetoolkit.rest.error.json.JsonParseMapException}

The json parse map exception is JsonParseMapException type.

* @see java.lang.String * @see java.lang.Class * @see java.util.Map * @see io.github.nichetoolkit.rest.error.json.JsonParseMapException */ public static Map> parseMapMap(String json, Class wrapKeyClazz, Class contentKeyClazz, Class contentValueClazz) throws JsonParseMapException { return parseMapMap(json, Map.class, Map.class, wrapKeyClazz, contentKeyClazz, contentValueClazz); } /** * parseResult *

The parse result method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param typeReference {@link com.fasterxml.jackson.core.type.TypeReference}

The type reference parameter is TypeReference type.

* @return {@link io.github.nichetoolkit.rest.RestResult}

The parse result return object is RestResult type.

* @throws JsonParseBeanException {@link io.github.nichetoolkit.rest.error.json.JsonParseBeanException}

The json parse bean exception is JsonParseBeanException type.

* @see java.lang.String * @see com.fasterxml.jackson.core.type.TypeReference * @see io.github.nichetoolkit.rest.RestResult * @see io.github.nichetoolkit.rest.error.json.JsonParseBeanException */ public static RestResult parseResult(String json, TypeReference> typeReference) throws JsonParseBeanException { return parseBean(json, typeReference); } /** * parseResult *

The parse result method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param clazz {@link java.lang.Class}

The clazz parameter is Class type.

* @return {@link io.github.nichetoolkit.rest.RestResult}

The parse result return object is RestResult type.

* @throws JsonParseBeanException {@link io.github.nichetoolkit.rest.error.json.JsonParseBeanException}

The json parse bean exception is JsonParseBeanException type.

* @see java.lang.String * @see java.lang.Class * @see io.github.nichetoolkit.rest.RestResult * @see io.github.nichetoolkit.rest.error.json.JsonParseBeanException */ public static RestResult parseResult(String json, Class clazz) throws JsonParseBeanException { JavaType javaType = TypeFactory.defaultInstance().constructParametricType(RestResult.class, clazz); return parseBean(json, javaType); } /** * parseResult *

The parse result method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param json {@link java.lang.String}

The json parameter is String type.

* @param innerType {@link com.fasterxml.jackson.databind.JavaType}

The inner type parameter is JavaType type.

* @return {@link io.github.nichetoolkit.rest.RestResult}

The parse result return object is RestResult type.

* @throws JsonParseBeanException {@link io.github.nichetoolkit.rest.error.json.JsonParseBeanException}

The json parse bean exception is JsonParseBeanException type.

* @see java.lang.String * @see com.fasterxml.jackson.databind.JavaType * @see io.github.nichetoolkit.rest.RestResult * @see io.github.nichetoolkit.rest.error.json.JsonParseBeanException */ public static RestResult parseResult(String json, JavaType innerType) throws JsonParseBeanException { JavaType javaType = TypeFactory.defaultInstance().constructParametricType(RestResult.class, innerType); return parseBean(json, javaType); } /** * parseResult *

The parse result method.

* @param json {@link java.lang.String}

The json parameter is String type.

* @return {@link io.github.nichetoolkit.rest.RestResult}

The parse result return object is RestResult type.

* @throws JsonParseBeanException {@link io.github.nichetoolkit.rest.error.json.JsonParseBeanException}

The json parse bean exception is JsonParseBeanException type.

* @see java.lang.String * @see io.github.nichetoolkit.rest.RestResult * @see io.github.nichetoolkit.rest.error.json.JsonParseBeanException */ public static RestResult parseResult(String json) throws JsonParseBeanException { if (GeneralUtils.isEmpty(json)) { return null; } try { JsonNode jsonNode = ObjectMapperHolder.objectMapper().readTree(json); if (GeneralUtils.isNotEmpty(jsonNode)) { RestResult restResult = new RestResult<>(); JsonNode status = jsonNode.get(RestResult.STATUS_NAME); if (GeneralUtils.isNotEmpty(status)) { restResult.setStatus(status.asInt()); } JsonNode message = jsonNode.get(RestResult.MESSAGE_NAME); if (GeneralUtils.isNotEmpty(message)) { restResult.setMessage(message.toString()); } JsonNode data = jsonNode.get(RestResult.DATA_NAME); if (GeneralUtils.isNotEmpty(data)) { restResult.setData(data.toString()); } return restResult; } return null; } catch (JsonProcessingException exception) { throw new JsonParseBeanException("parseResult", RestResult.class.getName(), json, exception.getMessage()); } } /** * parseConvert *

The parse convert method.

* @param {@link java.lang.Object}

The parameter can be of any type.

* @param value {@link java.lang.Object}

The value parameter is Object type.

* @param clazz {@link java.lang.Class}

The clazz parameter is Class type.

* @return T

The parse convert return object is T type.

* @throws ClassUnsupportedException {@link io.github.nichetoolkit.rest.error.ClassUnsupportedException}

The class unsupported exception is ClassUnsupportedException type.

* @see java.lang.Object * @see java.lang.Class * @see io.github.nichetoolkit.rest.error.ClassUnsupportedException */ public static T parseConvert(Object value, Class clazz) throws ClassUnsupportedException { if (GeneralUtils.isEmpty(value)) { return null; } try { if (value.getClass().equals(clazz)) { return ObjectMapperHolder.objectMapper().convertValue(value, clazz); } else { throw new ClassUnsupportedException("parseConvert",clazz.getName(),value.getClass().getName(), clazz.getName()); } } catch (Exception exception) { throw new ClassUnsupportedException(value.getClass().getName(), clazz.getName(), exception.getMessage()); } } }