mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 10:38:42 +08:00 
			
		
		
		
	优化代码,替换掉ToStringBuilder.reflectionToString相关代码
This commit is contained in:
		| @ -7,9 +7,6 @@ import java.util.Map; | ||||
| import java.util.concurrent.locks.Lock; | ||||
| import java.util.concurrent.locks.ReentrantLock; | ||||
|  | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||||
|  | ||||
| import cn.binarywang.wx.miniapp.config.WxMaConfig; | ||||
| import me.chanjar.weixin.common.bean.WxAccessToken; | ||||
| import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; | ||||
| @ -17,6 +14,7 @@ import me.chanjar.weixin.mp.api.WxMpConfigStorage; | ||||
| import me.chanjar.weixin.open.api.WxOpenConfigStorage; | ||||
| import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; | ||||
| import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; | ||||
| import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; | ||||
|  | ||||
| /** | ||||
|  * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化 | ||||
| @ -450,7 +448,7 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage { | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|       return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | ||||
|       return WxOpenGsonBuilder.create().toJson(this); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|  | ||||
| @ -1,20 +1,20 @@ | ||||
| package me.chanjar.weixin.open.bean.ma; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||||
|  | ||||
| import java.io.Serializable; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; | ||||
|  | ||||
| /** | ||||
|  * 微信小程序分类目录 | ||||
|  * 微信小程序分类目录. | ||||
|  * | ||||
|  * @author yqx | ||||
|  * @date 2018/9/13 | ||||
|  */ | ||||
| @Data | ||||
| public class WxOpenMaCategory implements Serializable { | ||||
|   private static final long serialVersionUID = -700005096619889630L; | ||||
|  | ||||
|   @SerializedName("first_class") | ||||
|   private String firstClass; | ||||
| @ -34,7 +34,8 @@ public class WxOpenMaCategory implements Serializable { | ||||
|   @SerializedName("third_id") | ||||
|   private Integer thirdId; | ||||
|  | ||||
|   @Override | ||||
|   public String toString() { | ||||
|     return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | ||||
|     return WxOpenGsonBuilder.create().toJson(this); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -1,12 +1,12 @@ | ||||
| package me.chanjar.weixin.open.bean.result; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import me.chanjar.weixin.open.bean.ma.WxOpenMaCategory; | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||||
|  | ||||
| import java.util.List; | ||||
| import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; | ||||
|  | ||||
| /** | ||||
|  * 微信开放平台小程序分类目录列表返回 | ||||
| @ -15,13 +15,16 @@ import java.util.List; | ||||
|  * @date 2018/9/12 | ||||
|  */ | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| public class WxOpenMaCategoryListResult extends WxOpenResult { | ||||
|   private static final long serialVersionUID = 4549360618179745721L; | ||||
|  | ||||
|   @SerializedName("category_list") | ||||
|   List<WxOpenMaCategory> categoryList; | ||||
|  | ||||
|   @Override | ||||
|   public String toString() { | ||||
|     return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | ||||
|     return WxOpenGsonBuilder.create().toJson(this); | ||||
|   } | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -1,18 +1,21 @@ | ||||
| package me.chanjar.weixin.open.bean.result; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
|  | ||||
| /** | ||||
|  * 微信开放平台小程序域名设置返回对象 | ||||
|  * 微信开放平台小程序域名设置返回对象. | ||||
|  * | ||||
|  * @author yqx | ||||
|  * @date 2018/9/12 | ||||
|  */ | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| public class WxOpenMaDomainResult extends WxOpenResult { | ||||
|   private static final long serialVersionUID = 3406315629639573330L; | ||||
|  | ||||
|   @SerializedName("requestdomain") | ||||
|   List<String> requestdomainList; | ||||
|  | ||||
| @ -1,26 +1,29 @@ | ||||
| package me.chanjar.weixin.open.bean.result; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; | ||||
|  | ||||
| /** | ||||
|  * 微信开放平台小程序第三方提交代码的页面配置列表 | ||||
|  * 微信开放平台小程序第三方提交代码的页面配置列表. | ||||
|  * | ||||
|  * @author yqx | ||||
|  * @date 2018/9/12 | ||||
|  */ | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| public class WxOpenMaPageListResult extends WxOpenResult { | ||||
|   private static final long serialVersionUID = 6982848180319905444L; | ||||
|  | ||||
|   @SerializedName("page_list") | ||||
|   List<String> pageList; | ||||
|  | ||||
|   @Override | ||||
|   public String toString() { | ||||
|     return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | ||||
|     return WxOpenGsonBuilder.create().toJson(this); | ||||
|   } | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -2,26 +2,31 @@ package me.chanjar.weixin.open.bean.result; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
|  | ||||
| /** | ||||
|  * . | ||||
|  * @author yqx | ||||
|  * @date 2018/10/3 | ||||
|  */ | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| public class WxOpenMaQueryAuditResult extends WxOpenResult { | ||||
|   private static final long serialVersionUID = 8022192589710319473L; | ||||
|  | ||||
|   /** | ||||
|    * 审核编号 | ||||
|    * 审核编号. | ||||
|    */ | ||||
|   @SerializedName("auditid") | ||||
|   Long auditId; | ||||
|  | ||||
|   /** | ||||
|    * 审核状态:2-审核中,0-审核通过,1-审核失败 | ||||
|    * 审核状态:2-审核中,0-审核通过,1-审核失败. | ||||
|    */ | ||||
|   Integer status; | ||||
|  | ||||
|   /** | ||||
|    * 审核失败原因 | ||||
|    * 审核失败原因. | ||||
|    */ | ||||
|   String reason; | ||||
| } | ||||
|  | ||||
| @ -2,18 +2,21 @@ package me.chanjar.weixin.open.bean.result; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
|  | ||||
| /** | ||||
|  * 微信开放平台小程序发布代码审核结果 | ||||
|  * 微信开放平台小程序发布代码审核结果. | ||||
|  * | ||||
|  * @author yqx | ||||
|  * @date 2018/9/12 | ||||
|  */ | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| public class WxOpenMaSubmitAuditResult extends WxOpenResult { | ||||
|   private static final long serialVersionUID = 7431725910039734365L; | ||||
|  | ||||
|   /** | ||||
|    * 审核编号 | ||||
|    * 审核编号. | ||||
|    */ | ||||
|   @SerializedName("auditid") | ||||
|   Long auditId; | ||||
|  | ||||
| @ -1,27 +1,30 @@ | ||||
| package me.chanjar.weixin.open.bean.result; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import me.chanjar.weixin.open.bean.ma.WxOpenMaMember; | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import me.chanjar.weixin.open.bean.ma.WxOpenMaMember; | ||||
| import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; | ||||
|  | ||||
| /** | ||||
|  * 微信开放平台小程序体验者列表返回 | ||||
|  * 微信开放平台小程序体验者列表返回. | ||||
|  * | ||||
|  * @author yqx | ||||
|  * @date 2018/9/12 | ||||
|  */ | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = false) | ||||
| public class WxOpenMaTesterListResult extends WxOpenResult { | ||||
|   private static final long serialVersionUID = -613936397557067111L; | ||||
|  | ||||
|   @SerializedName("members") | ||||
|   List<WxOpenMaMember> membersList; | ||||
|  | ||||
|   @Override | ||||
|   public String toString() { | ||||
|     return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | ||||
|     return WxOpenGsonBuilder.create().toJson(this); | ||||
|   } | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -1,33 +1,33 @@ | ||||
| package me.chanjar.weixin.open.bean.result; | ||||
|  | ||||
| import lombok.Data; | ||||
| import org.apache.commons.lang3.StringUtils; | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||||
|  | ||||
| import java.io.Serializable; | ||||
|  | ||||
| import org.apache.commons.lang3.StringUtils; | ||||
|  | ||||
| import lombok.Data; | ||||
| import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; | ||||
|  | ||||
| /** | ||||
|  * 基础的微信开放平台请求结果 | ||||
|  * 基础的微信开放平台请求结果. | ||||
|  * | ||||
|  * @author yqx | ||||
|  * @date 2018/10/1 | ||||
|  */ | ||||
| @Data | ||||
| public class WxOpenResult implements Serializable { | ||||
|   private static final long serialVersionUID = 2101652152604850904L; | ||||
|   protected String errcode; | ||||
|   protected String errmsg; | ||||
|  | ||||
|   /** | ||||
|    * 请求是否成功 | ||||
|    * | ||||
|    * @return | ||||
|    * 请求是否成功. | ||||
|    */ | ||||
|   public boolean isSuccess() { | ||||
|     return StringUtils.equalsIgnoreCase(errcode, "0"); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public String toString() { | ||||
|     return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | ||||
|     return WxOpenGsonBuilder.create().toJson(this); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -1,13 +1,17 @@ | ||||
| package me.chanjar.weixin.open.util.json; | ||||
|  | ||||
| import com.google.gson.*; | ||||
| import java.lang.reflect.Type; | ||||
|  | ||||
| import com.google.gson.JsonDeserializationContext; | ||||
| import com.google.gson.JsonDeserializer; | ||||
| import com.google.gson.JsonElement; | ||||
| import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParseException; | ||||
| import com.google.gson.reflect.TypeToken; | ||||
| import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; | ||||
| import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizerInfo; | ||||
| import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; | ||||
|  | ||||
| import java.lang.reflect.Type; | ||||
|  | ||||
| /** | ||||
|  * @author <a href="https://github.com/007gzs">007</a> | ||||
|  */ | ||||
| @ -17,12 +21,12 @@ public class WxOpenAuthorizerInfoResultGsonAdapter implements JsonDeserializer<W | ||||
|     WxOpenAuthorizerInfoResult authorizerInfoResult = new WxOpenAuthorizerInfoResult(); | ||||
|     JsonObject jsonObject = jsonElement.getAsJsonObject(); | ||||
|  | ||||
|     WxOpenAuthorizationInfo authorizationInfo = WxOpenGsonBuilder.INSTANCE.create().fromJson(jsonObject.get("authorization_info"), | ||||
|     WxOpenAuthorizationInfo authorizationInfo = WxOpenGsonBuilder.create().fromJson(jsonObject.get("authorization_info"), | ||||
|       new TypeToken<WxOpenAuthorizationInfo>() { | ||||
|       }.getType()); | ||||
|  | ||||
|     authorizerInfoResult.setAuthorizationInfo(authorizationInfo); | ||||
|     WxOpenAuthorizerInfo authorizerInfo = WxOpenGsonBuilder.INSTANCE.create().fromJson(jsonObject.get("authorizer_info"), | ||||
|     WxOpenAuthorizerInfo authorizerInfo = WxOpenGsonBuilder.create().fromJson(jsonObject.get("authorizer_info"), | ||||
|       new TypeToken<WxOpenAuthorizerInfo>() { | ||||
|       }.getType()); | ||||
|  | ||||
|  | ||||
| @ -15,7 +15,7 @@ import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; | ||||
|  */ | ||||
| public class WxOpenGsonBuilder { | ||||
|  | ||||
|   public static final GsonBuilder INSTANCE = new GsonBuilder(); | ||||
|   private static final GsonBuilder INSTANCE = new GsonBuilder(); | ||||
|  | ||||
|   static { | ||||
|     INSTANCE.disableHtmlEscaping(); | ||||
|  | ||||
| @ -1,12 +1,16 @@ | ||||
| package me.chanjar.weixin.open.util.json; | ||||
|  | ||||
| import com.google.gson.*; | ||||
| import java.lang.reflect.Type; | ||||
|  | ||||
| import com.google.gson.JsonDeserializationContext; | ||||
| import com.google.gson.JsonDeserializer; | ||||
| import com.google.gson.JsonElement; | ||||
| import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParseException; | ||||
| import com.google.gson.reflect.TypeToken; | ||||
| import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; | ||||
| import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; | ||||
|  | ||||
| import java.lang.reflect.Type; | ||||
|  | ||||
| /** | ||||
|  * @author <a href="https://github.com/007gzs">007</a> | ||||
|  */ | ||||
| @ -16,7 +20,7 @@ public class WxOpenQueryAuthResultGsonAdapter implements JsonDeserializer<WxOpen | ||||
|     WxOpenQueryAuthResult queryAuthResult = new WxOpenQueryAuthResult(); | ||||
|     JsonObject jsonObject = jsonElement.getAsJsonObject(); | ||||
|  | ||||
|     WxOpenAuthorizationInfo authorizationInfo = WxOpenGsonBuilder.INSTANCE.create().fromJson(jsonObject.get("authorization_info"), | ||||
|     WxOpenAuthorizationInfo authorizationInfo = WxOpenGsonBuilder.create().fromJson(jsonObject.get("authorization_info"), | ||||
|       new TypeToken<WxOpenAuthorizationInfo>() { | ||||
|       }.getType()); | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Binary Wang
					Binary Wang