pro.jk.ejoker.common.service.impl.JSONConverterUseJsonSmartImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ejoker-common Show documentation
Show all versions of ejoker-common Show documentation
EJoker is a CQRS + EventSourcing framwork
package pro.jk.ejoker.common.service.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.minidev.json.JSONObject;
import net.minidev.json.JSONStyle;
import net.minidev.json.JSONValue;
import net.minidev.json.parser.ParseException;
import pro.jk.ejoker.common.context.annotation.context.Dependence;
import pro.jk.ejoker.common.context.annotation.context.EService;
import pro.jk.ejoker.common.service.IJSONConverter;
import pro.jk.ejoker.common.service.IJSONObjectConverter;
@EService
public class JSONConverterUseJsonSmartImpl implements IJSONConverter {
private final static Logger logger = LoggerFactory.getLogger(JSONConverterUseJsonSmartImpl.class);
@Dependence
private IJSONObjectConverter jsonObjectConverter;
@Override
public String convert(T object) {
JSONObject result = jsonObjectConverter.convert(object);
return JSONValue.toJSONString(result, JSONStyle.NO_COMPRESS);
}
@Override
public T revert(String jsonString, Class clazz) {
try {
return jsonObjectConverter.revert((JSONObject )JSONValue.parseStrict(jsonString), clazz);
} catch (ParseException e) {
logger.error("revert JsonObject failed!!!", e);
throw new RuntimeException("revert JsonObject failed!!!", e);
}
}
}