{"record":{"id":"59a68290fe5d4de1","repo":"binarywang/WxJava","slug":"expected-boolean-or-number-but-was-peek","errorCode":null,"errorMessage":"Expected BOOLEAN or NUMBER but was {peek}","messagePattern":"Expected BOOLEAN or NUMBER but was (.+?)","errorType":"exception","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxBooleanTypeAdapter.java","lineNumber":44,"sourceCode":"      out.value(value);\n    }\n  }\n\n  @Override\n  public Boolean read(JsonReader in) throws IOException {\n    JsonToken peek = in.peek();\n    switch (peek) {\n      case BOOLEAN:\n        return in.nextBoolean();\n      case NULL:\n        in.nextNull();\n        return null;\n      case NUMBER:\n        return BooleanUtils.toBoolean(in.nextInt());\n      case STRING:\n        return BooleanUtils.toBoolean(in.nextString());\n      default:\n        throw new JsonParseException(\"Expected BOOLEAN or NUMBER but was \" + peek);\n    }\n  }\n}\n","sourceCodeStart":26,"sourceCodeEnd":48,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxBooleanTypeAdapter.java#L26-L48","documentation":"Thrown by WxBooleanTypeAdapter during Gson deserialization when the JSON token is none of BOOLEAN, NULL, NUMBER, STRING. The adapter tolerantly coerces booleans, nulls, 0/1 numbers and true/false strings, but any other token shape (object, array, name) is rejected as a JsonParseException.","triggerScenarios":"A field mapped to Boolean arrives from WeChat as a JSON object or array (schema drift), or a numeric-boolean field arrives as a nested structure; also when the wrong type adapter is bound to a field whose server representation changed.","commonSituations":"WeChat changes a boolean field to an object on a new API version; a custom DTO reuses a Boolean-typed field for a richer payload; response intercepted/rewritten by a proxy injects an object.","solutions":["Inspect the raw JSON response (enable debug logging) to see the actual token for the offending field.","Change the field type or add a custom adapter that handles the new shape.","Pin the WxJava version to one matching the WeChat API contract you target."],"exampleFix":"// before\n@SerializedName(\"enabled\") private Boolean enabled;\n// after - server now returns {\"value\":true}\n@SerializedName(\"enabled\") private EnabledWrapper enabled;","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  MyBean b = gson.fromJson(json, MyBean.class);\n} catch (JsonParseException e) {\n  log.error(\"failed parsing boolean field; raw={}\", json);\n  throw e;\n}","preventionTips":["Log the raw JSON before deserialization when fields are flaky.","Pin the WxJava version to the WeChat API contract you target.","Register a custom adapter if the server format changed."],"tags":["gson","json","type-adapter","deserialization"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}