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

com.github.bingoohuang.springrestclient.utils.Beans Maven / Gradle / Ivy

There is a newer version: 0.0.23
Show newest version
package com.github.bingoohuang.springrestclient.utils;

import com.alibaba.fastjson.JSON;
import com.github.bingoohuang.springrestclient.xml.Xmls;
import com.github.bingoohuang.utils.codec.Json;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Type;

@UtilityClass
public class Beans {
    public Object unmarshal(String text, Class clazz) {
        if (StringUtils.isEmpty(text)) return null;

        return text.startsWith("<")
            ? Xmls.unmarshal(text, clazz)
            : (text.startsWith("{")
            ? Json.unJson(text, clazz)
            : Json.unJsonArray(text, clazz));
    }

    public Object unmarshal(String text, Type returnType) {
        return JSON.parseObject(text, returnType);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy