io.github.nichetoolkit.rest.helper.DeserializeHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-toolkit-utils Show documentation
Show all versions of rest-toolkit-utils Show documentation
Rest toolkit utils project for Spring Boot
The newest version!
package io.github.nichetoolkit.rest.helper;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import io.github.nichetoolkit.rest.error.supply.JsonDeserializeException;
import java.io.IOException;
import java.util.*;
/**
* DeserializeHelper
* The deserialize helper class.
* @author Cyan ([email protected])
* @since Jdk1.8
*/
public class DeserializeHelper {
/**
* deserializerBean
* The deserializer bean method.
* @param parser {@link com.fasterxml.jackson.core.JsonParser} The parser parameter is JsonParser
type.
* @return {@link java.util.Map} The deserializer bean return object is Map
type.
* @throws JsonDeserializeException {@link io.github.nichetoolkit.rest.error.supply.JsonDeserializeException} The json deserialize exception is JsonDeserializeException
type.
* @see com.fasterxml.jackson.core.JsonParser
* @see java.util.Map
* @see io.github.nichetoolkit.rest.error.supply.JsonDeserializeException
*/
public static Map deserializerBean(JsonParser parser) throws JsonDeserializeException {
try {
JsonNode jsonNode = parser.getCodec().readTree(parser);
Map beanMap = new HashMap<>();
if (!jsonNode.isArray()) {
buildBeanMap(jsonNode, beanMap);
}
return beanMap;
} catch (IOException exception) {
throw new JsonDeserializeException(exception.getMessage());
}
}
/**
* deserializerList
* The deserializer list method.
* @param parser {@link com.fasterxml.jackson.core.JsonParser} The parser parameter is JsonParser
type.
* @return {@link java.util.List} The deserializer list return object is List
type.
* @throws JsonDeserializeException {@link io.github.nichetoolkit.rest.error.supply.JsonDeserializeException} The json deserialize exception is JsonDeserializeException
type.
* @see com.fasterxml.jackson.core.JsonParser
* @see java.util.List
* @see io.github.nichetoolkit.rest.error.supply.JsonDeserializeException
*/
public static List