mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-15 18:55:13 +08:00
#68 实现获取公众号的自动回复规则的接口
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package me.chanjar.weixin.common.util.json;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Gson 布尔类型类型转换器
|
||||
* Created by Binary Wang on 2017-7-8.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class WxBooleanTypeAdapter extends TypeAdapter<Boolean> {
|
||||
@Override
|
||||
public void write(JsonWriter out, Boolean value) throws IOException {
|
||||
if (value == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
out.value(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean read(JsonReader in) throws IOException {
|
||||
JsonToken peek = in.peek();
|
||||
switch (peek) {
|
||||
case BOOLEAN:
|
||||
return in.nextBoolean();
|
||||
case NULL:
|
||||
in.nextNull();
|
||||
return null;
|
||||
case NUMBER:
|
||||
return BooleanUtils.toBoolean(in.nextInt());
|
||||
case STRING:
|
||||
return BooleanUtils.toBoolean(in.nextString());
|
||||
default:
|
||||
throw new JsonParseException("Expected BOOLEAN or NUMBER but was " + peek);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package me.chanjar.weixin.common.util.json;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Gson 日期类型转换器
|
||||
* Created by Binary Wang on 2017-7-8.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class WxDateTypeAdapter extends TypeAdapter<Date> {
|
||||
@Override
|
||||
public void write(JsonWriter out, Date value) throws IOException {
|
||||
if (value == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
out.value(value.getTime() / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date read(JsonReader in) throws IOException {
|
||||
JsonToken peek = in.peek();
|
||||
switch (peek) {
|
||||
case NULL:
|
||||
in.nextNull();
|
||||
return null;
|
||||
case NUMBER:
|
||||
return new Date(in.nextInt() * 1000);
|
||||
default:
|
||||
throw new JsonParseException("Expected NUMBER but was " + peek);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user