有人知道如何将这段代码转换为 Kotlin 吗?
GsonBuilder builder = new GsonBuilder();
builder.setLenient();
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json.getAsJsonPrimitive().isNumber()) {
return new Date(json.getAsJsonPrimitive().getAsLong() * 1000);
} else {
return null;
}
}
});
return builder.create();
然后,我尝试了
val builder = GsonBuilder()
builder.setLenient()
builder.registerTypeAdapter(Date::class.java,.........)
return builder.create()
......我无法弄清楚如何将代码转换