#68 实现获取公众号的自动回复规则的接口

This commit is contained in:
Binary Wang
2017-07-08 19:22:26 +08:00
committed by Binary Wang
parent 62c1d61bcf
commit 94724670da
7 changed files with 647 additions and 6 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}