mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-28 12:37:55 +08:00
删除不稳定的ToStringUtils自定义类
This commit is contained in:
@ -1,10 +1,12 @@
|
||||
package me.chanjar.weixin.common.bean;
|
||||
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.ToStringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 卡券Api签名.
|
||||
*
|
||||
@ -35,7 +37,6 @@ public class WxCardApiSignature implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringUtils.toSimpleString(this);
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
package me.chanjar.weixin.common.bean.menu;
|
||||
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.ToStringUtils;
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Serializable;
|
||||
@ -11,6 +7,12 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
|
||||
/**
|
||||
* 菜单(公众号和企业号共用的).
|
||||
*
|
||||
@ -47,7 +49,7 @@ public class WxMenu implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringUtils.toSimpleString(this);
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
package me.chanjar.weixin.common.bean.menu;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.ToStringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WxMenuButton implements Serializable {
|
||||
private static final long serialVersionUID = -1070939403109776555L;
|
||||
@ -76,7 +78,7 @@ public class WxMenuButton implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringUtils.toSimpleString(this);
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
package me.chanjar.weixin.common.bean.menu;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.ToStringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class WxMenuRule implements Serializable {
|
||||
@ -24,6 +26,6 @@ public class WxMenuRule implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringUtils.toSimpleString(this);
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package me.chanjar.weixin.common.bean.result;
|
||||
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.ToStringUtils;
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
|
||||
@Data
|
||||
public class WxMediaUploadResult implements Serializable {
|
||||
private static final long serialVersionUID = 330834334738622341L;
|
||||
@ -21,7 +23,7 @@ public class WxMediaUploadResult implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringUtils.toSimpleString(this);
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
package me.chanjar.weixin.common.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 自定义的ToString方法,用于产生去掉空值属性的字符串
|
||||
* Created by Binary Wang on 2016-10-27.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class ToStringUtils {
|
||||
public static final ToStringStyle THE_STYLE = new SimpleMultiLineToStringStyle();
|
||||
|
||||
/**
|
||||
* 用于产生去掉空值属性并以换行符分割各属性键值的toString字符串
|
||||
*
|
||||
* @param obj
|
||||
*/
|
||||
public static String toSimpleString(Object obj) {
|
||||
String toStringResult = ToStringBuilder.reflectionToString(obj, THE_STYLE);
|
||||
String[] split = toStringResult.split(SimpleMultiLineToStringStyle.LINE_SEPARATOR);
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String string : split) {
|
||||
if (string.endsWith(SimpleMultiLineToStringStyle.NULL_TEXT)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.append(string + SimpleMultiLineToStringStyle.LINE_SEPARATOR);
|
||||
}
|
||||
|
||||
if (result.length() == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
//如果没有非空的属性,就输出 <all null properties>
|
||||
if (StringUtils.countMatches(result, SimpleMultiLineToStringStyle.LINE_SEPARATOR) == 2) {
|
||||
return result.toString().split(SimpleMultiLineToStringStyle.LINE_SEPARATOR)[0]
|
||||
+ "<all null values>]";
|
||||
}
|
||||
|
||||
return result.deleteCharAt(result.length() - 1).toString();
|
||||
}
|
||||
|
||||
private static class SimpleMultiLineToStringStyle extends ToStringStyle {
|
||||
private static final long serialVersionUID = 4645306494220335355L;
|
||||
private static final String LINE_SEPARATOR = "\n";
|
||||
private static final String NULL_TEXT = "<null>";
|
||||
|
||||
public SimpleMultiLineToStringStyle() {
|
||||
super();
|
||||
this.setContentStart("[");
|
||||
this.setFieldSeparator(LINE_SEPARATOR + " ");
|
||||
this.setFieldSeparatorAtStart(true);
|
||||
this.setContentEnd(LINE_SEPARATOR + "]");
|
||||
this.setNullText(NULL_TEXT);
|
||||
this.setUseShortClassName(true);
|
||||
this.setUseIdentityHashCode(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user