
com.github.bingoohuang.utils.json.Jsons Maven / Gradle / Ivy
package com.github.bingoohuang.utils.json;
import com.alibaba.fastjson.JSON;
import com.github.bingoohuang.utils.type.Generic;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import java.lang.reflect.Field;
@Slf4j
public class Jsons {
@SuppressWarnings("unchecked")
public static T parseJson(String json, Field field) {
val genericType = Generic.getMapParameterizedType(field.getGenericType());
return (T) JSON.parseObject(json, genericType);
}
public static T parse(String json, Class tClass, boolean silent) {
try {
return JSON.parseObject(json, tClass);
} catch (Exception e) {
if (silent) {
log.warn("parse json {} fail", json, e);
return null;
}
throw new RuntimeException("parse json error " + e.getMessage() + " for " + json);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy