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

com.blade.kit.json.DefaultJsonSupport Maven / Gradle / Ivy

There is a newer version: 2.0.15.RELEASE
Show newest version
package com.blade.kit.json;

import com.blade.kit.ReflectKit;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Type;

/**
 * @author biezhi
 * @date 2017/12/15
 */
@Slf4j
public class DefaultJsonSupport implements JsonSupport {

    @Override
    public String toString(Object object) {
        return toString(object, SerializeMapping.defaultMapping());
    }

    @Override
    public  T formJson(String json, Type type) {
        Object jsonObj = SampleJsonSerializer.deserialize(json);
        Class cls = (Class) ReflectKit.typeToClass(type);
        return BeanSerializer.deserialize(cls, jsonObj);
    }

    public String toString(Object object, SerializeMapping serializeMapping) {
        try {
            Object jsonObj = BeanSerializer.serialize(serializeMapping, object);
            return SampleJsonSerializer.serialize(jsonObj);
        } catch (Exception e) {
            log.error("object to json string error", e);
            return null;
        }
    }

    public Ason toAson(String json) {
        Object jsonObj = SampleJsonSerializer.deserialize(json);
        return (Ason) jsonObj;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy