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

pro.jk.ejoker.common.service.impl.JSONConverterUseJsonSmartImpl Maven / Gradle / Ivy

There is a newer version: 3.0.7.1
Show newest version
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);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy