{"record":{"id":"1c42a48b3c9dd172","repo":"binarywang/WxJava","slug":"expected-number-but-was-peek","errorCode":null,"errorMessage":"Expected NUMBER but was {peek}","messagePattern":"Expected NUMBER but was (.+?)","errorType":"exception","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxDateTypeAdapter.java","lineNumber":40,"sourceCode":"  public void write(JsonWriter out, Date value) throws IOException {\n    if (value == null) {\n      out.nullValue();\n    } else {\n      out.value(value.getTime() / 1000);\n    }\n  }\n\n  @Override\n  public Date read(JsonReader in) throws IOException {\n    JsonToken peek = in.peek();\n    switch (peek) {\n      case NULL:\n        in.nextNull();\n        return null;\n      case NUMBER:\n        return new Date(in.nextInt() * 1000);\n      default:\n        throw new JsonParseException(\"Expected NUMBER but was \" + peek);\n    }\n  }\n}\n","sourceCodeStart":22,"sourceCodeEnd":44,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxDateTypeAdapter.java#L22-L44","documentation":"Thrown by WxDateTypeAdapter during deserialization when the JSON token is neither NULL nor NUMBER. The adapter only understands epoch seconds (multiplied by 1000 to form a Date); a string date, object, or array triggers this JsonParseException.","triggerScenarios":"A Date field receives a string timestamp (e.g. \"2024-01-01\" or a millisecond string) instead of a numeric epoch; the server format changed; the field is bound to this adapter but carries unrelated data.","commonSituations":"WeChat returns a formatted date string for a field previously sent as epoch; mixing this adapter with fields that actually carry ISO dates; version skew between server format and adapter.","solutions":["Log the raw response to confirm the token type of the date field.","Use a string-typed field and parse it with the appropriate format, or register an adapter that also handles STRING.","Verify the WxJava version matches the API contract for that field."],"exampleFix":"// before - epoch expected but server sends string\n@SerializedName(\"create_time\") private Date createTime; // WxDateTypeAdapter\n// after\n@SerializedName(\"create_time\") private String createTime; // parse manually","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  MyBean b = gson.fromJson(json, MyBean.class);\n} catch (JsonParseException e) {\n  log.error(\"date parse failed; raw={}\", json);\n  throw e;\n}","preventionTips":["Confirm whether the field is epoch-seconds or a date string.","Use a String field and parse manually if format varies.","Keep the WxJava version aligned with the API contract."],"tags":["gson","json","type-adapter","date","deserialization"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}