
com.magictools.json.JSONSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magic-tools-all Show documentation
Show all versions of magic-tools-all Show documentation
magic-tools 是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
The newest version!
package com.magictools.json;
import com.magictools.core.bean.BeanUtil;
/**
* JSON支持
* 继承此类实现实体类与JSON的相互转换
*
* @author Looly
*/
public class JSONSupport implements JSONString, JSONBeanParser {
/**
* JSON String转Bean
*
* @param jsonString JSON String
*/
public void parse(String jsonString) {
parse(new JSONObject(jsonString));
}
/**
* JSON转Bean
*
* @param json JSON
*/
@Override
public void parse(JSON json) {
final JSONSupport support = JSONConverter.jsonToBean(getClass(), json, false);
BeanUtil.copyProperties(support, this);
}
/**
* @return JSON对象
*/
public JSONObject toJSON() {
return new JSONObject(this);
}
@Override
public String toJSONString() {
return toJSON().toString();
}
/**
* 美化的JSON(使用回车缩进显示JSON),用于打印输出debug
*
* @return 美化的JSON
*/
public String toPrettyString() {
return toJSON().toStringPretty();
}
@Override
public String toString() {
return toJSONString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy