mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
issue #28 添加语义理解接口
This commit is contained in:
@@ -23,6 +23,7 @@ public class WxMpGsonBuilder {
|
||||
INSTANCE.registerTypeAdapter(WxMpMassUploadResult.class, new WxMpMassUploadResultAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpQrCodeTicket.class, new WxQrCodeTicketAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpTemplateMessage.class, new WxMpTemplateMessageGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpSemanticQueryResult.class, new WxMpSemanticQueryResultAdapter());
|
||||
}
|
||||
|
||||
public static Gson create() {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
package me.chanjar.weixin.mp.util.json;
|
||||
|
||||
import com.google.gson.*;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Daniel Qian
|
||||
*
|
||||
*/
|
||||
public class WxMpSemanticQueryResultAdapter implements JsonDeserializer<WxMpSemanticQueryResult> {
|
||||
|
||||
public WxMpSemanticQueryResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
WxMpSemanticQueryResult result = new WxMpSemanticQueryResult();
|
||||
JsonObject resultJsonObject = json.getAsJsonObject();
|
||||
|
||||
if (GsonHelper.getString(resultJsonObject, "query") != null) {
|
||||
result.setQuery(GsonHelper.getString(resultJsonObject, "query"));
|
||||
}
|
||||
if (GsonHelper.getString(resultJsonObject, "type") != null) {
|
||||
result.setType(GsonHelper.getString(resultJsonObject, "type"));
|
||||
}
|
||||
if (resultJsonObject.get("semantic") != null) {
|
||||
result.setSemantic(resultJsonObject.get("semantic").toString());
|
||||
}
|
||||
if (resultJsonObject.get("result") != null) {
|
||||
result.setResult(resultJsonObject.get("result").toString());
|
||||
}
|
||||
if (GsonHelper.getString(resultJsonObject, "answer") != null) {
|
||||
result.setAnswer(GsonHelper.getString(resultJsonObject, "answer"));
|
||||
}
|
||||
if (GsonHelper.getString(resultJsonObject, "text") != null) {
|
||||
result.setText(GsonHelper.getString(resultJsonObject, "text"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user