mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
add config
This commit is contained in:
@@ -4,26 +4,41 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* JSON配置项
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.1.19
|
||||
*/
|
||||
public class JSONConfig implements Serializable {
|
||||
private static final long serialVersionUID = 119730355204738278L;
|
||||
|
||||
/** 是否有序,顺序按照加入顺序排序 */
|
||||
/**
|
||||
* 是否有序,顺序按照加入顺序排序
|
||||
*/
|
||||
private boolean order;
|
||||
/** 是否忽略转换过程中的异常 */
|
||||
/**
|
||||
* 是否忽略转换过程中的异常
|
||||
*/
|
||||
private boolean ignoreError;
|
||||
/** 是否忽略键的大小写 */
|
||||
/**
|
||||
* 是否忽略键的大小写
|
||||
*/
|
||||
private boolean ignoreCase;
|
||||
/** 日期格式,null表示默认的时间戳 */
|
||||
/**
|
||||
* 日期格式,null表示默认的时间戳
|
||||
*/
|
||||
private String dateFormat;
|
||||
/** 是否忽略null值 */
|
||||
/**
|
||||
* 是否忽略null值
|
||||
*/
|
||||
private boolean ignoreNullValue = true;
|
||||
|
||||
/**
|
||||
* 是否忽略transient关键字修饰的字段
|
||||
*/
|
||||
private boolean ignoreTransient = true;
|
||||
|
||||
/**
|
||||
* 创建默认的配置项
|
||||
*
|
||||
* @return JSONConfig
|
||||
*/
|
||||
public static JSONConfig create() {
|
||||
@@ -32,7 +47,7 @@ public class JSONConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 是否有序,顺序按照加入顺序排序
|
||||
*
|
||||
*
|
||||
* @return 是否有序
|
||||
*/
|
||||
public boolean isOrder() {
|
||||
@@ -41,7 +56,7 @@ public class JSONConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 设置是否有序,顺序按照加入顺序排序
|
||||
*
|
||||
*
|
||||
* @param order 是否有序
|
||||
* @return this
|
||||
*/
|
||||
@@ -52,7 +67,7 @@ public class JSONConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 是否忽略转换过程中的异常
|
||||
*
|
||||
*
|
||||
* @return 是否忽略转换过程中的异常
|
||||
*/
|
||||
public boolean isIgnoreError() {
|
||||
@@ -61,7 +76,7 @@ public class JSONConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 设置是否忽略转换过程中的异常
|
||||
*
|
||||
*
|
||||
* @param ignoreError 是否忽略转换过程中的异常
|
||||
* @return this
|
||||
*/
|
||||
@@ -72,7 +87,7 @@ public class JSONConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 是否忽略键的大小写
|
||||
*
|
||||
*
|
||||
* @return 是否忽略键的大小写
|
||||
*/
|
||||
public boolean isIgnoreCase() {
|
||||
@@ -81,7 +96,7 @@ public class JSONConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 设置是否忽略键的大小写
|
||||
*
|
||||
*
|
||||
* @param ignoreCase 是否忽略键的大小写
|
||||
* @return this
|
||||
*/
|
||||
@@ -92,7 +107,7 @@ public class JSONConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 日期格式,null表示默认的时间戳
|
||||
*
|
||||
*
|
||||
* @return 日期格式,null表示默认的时间戳
|
||||
*/
|
||||
public String getDateFormat() {
|
||||
@@ -101,7 +116,7 @@ public class JSONConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 设置日期格式,null表示默认的时间戳
|
||||
*
|
||||
*
|
||||
* @param dateFormat 日期格式,null表示默认的时间戳
|
||||
* @return this
|
||||
*/
|
||||
@@ -109,10 +124,10 @@ public class JSONConfig implements Serializable {
|
||||
this.dateFormat = dateFormat;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否忽略null值
|
||||
*
|
||||
*
|
||||
* @return 是否忽略null值
|
||||
*/
|
||||
public boolean isIgnoreNullValue() {
|
||||
@@ -121,7 +136,7 @@ public class JSONConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 设置是否忽略null值
|
||||
*
|
||||
*
|
||||
* @param ignoreNullValue 是否忽略null值
|
||||
* @return this
|
||||
*/
|
||||
@@ -129,4 +144,26 @@ public class JSONConfig implements Serializable {
|
||||
this.ignoreNullValue = ignoreNullValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否忽略transient关键字修饰的字段
|
||||
*
|
||||
* @return 是否忽略transient关键字修饰的字段
|
||||
* @since 5.3.11
|
||||
*/
|
||||
public boolean isIgnoreTransient() {
|
||||
return this.ignoreTransient;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否忽略transient关键字修饰的字段
|
||||
*
|
||||
* @param ignoreTransient 是否忽略transient关键字修饰的字段
|
||||
* @return this
|
||||
* @since 5.3.11
|
||||
*/
|
||||
public JSONConfig setIgnoreTransient(boolean ignoreTransient) {
|
||||
this.ignoreTransient = ignoreTransient;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@@ -625,6 +625,11 @@ public class JSONObject implements JSON, JSONGetter<String>, Map<String, Object>
|
||||
Method getter;
|
||||
Object value;
|
||||
for (PropDesc prop : props) {
|
||||
if(this.config.isIgnoreTransient() && prop.isTransient()){
|
||||
// 忽略Transient字段和方法
|
||||
continue;
|
||||
}
|
||||
|
||||
// 得到property对应的getter方法
|
||||
getter = prop.getGetter();
|
||||
if (null == getter) {
|
||||
|
Reference in New Issue
Block a user