{"record":{"id":"7ea282cbf089de89","repo":"hs-web/hsweb-framework","slug":"parse-enum-type-error-value-value","errorCode":null,"errorMessage":"parse enum \" + type + \" error, value : \" + value","messagePattern":"parse enum \" \\+ type \\+ \" error, value : \" \\+ value","errorType":"exception","errorClass":"JSONException","httpStatus":null,"severity":"error","filePath":"hsweb-core/src/main/java/org/hswebframework/web/dict/EnumDict.java","lineNumber":371,"sourceCode":"                    if (name.length() == 0) {\n                        return (T) null;\n                    }\n                    return (T) EnumDict.find((Class) type, name).orElse(null);\n                } else if (token == JSONToken.NULL) {\n                    lexer.nextToken(JSONToken.COMMA);\n                    return null;\n                } else {\n                    value = parser.parse();\n                    if (value instanceof Map) {\n                        return (T) EnumDict.find(((Class) type), ((Map) value).get(\"value\"))\n                                           .orElseGet(() ->\n                                                          EnumDict\n                                                              .find(((Class) type), ((Map) value).get(\"text\"))\n                                                              .orElse(null));\n                    }\n                }\n\n                throw new JSONException(\"parse enum \" + type + \" error, value : \" + value);\n            } catch (JSONException e) {\n                throw e;\n            } catch (Exception e) {\n                throw new JSONException(e.getMessage(), e);\n            }\n        }\n\n        @Override\n        public int getFastMatchToken() {\n            return JSONToken.LITERAL_STRING;\n        }\n\n        @Override\n        @SuppressWarnings(\"all\")\n        @SneakyThrows\n        public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {\n            JsonNode node = jp.getCodec().readTree(jp);\n            if (mapper != null) {","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/hs-web/hsweb-framework/blob/b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8/hsweb-core/src/main/java/org/hswebframework/web/dict/EnumDict.java#L353-L389","documentation":"EnumDict's fastjson deserializer cannot convert the incoming JSON value into an enum that implements EnumDict. It looks the value up via EnumDict.find by 'text' (or value/id) and throws JSONException when no enum constant matches.","triggerScenarios":"Deserializing JSON into an EnumDict enum where the value (or its 'text'/'value'/'id' field) does not match any enum constant, or the target type is not actually an EnumDict enum (e.g. a plain String or Integer passed as `type`).","commonSituations":"Front-end sends a renamed/legacy dict label or ID; dictionary data changed in the database but enum constants were not updated; deserializing a plain enum that doesn't implement EnumDict; client sends an object without a 'text' key.","solutions":["Make the enum implement EnumDict and define constants whose value/text cover all client inputs","Update the client payload to send a valid enum value/text","Add the missing dictionary item to the enum constants","Check the JSON structure: send {\"text\":\"...\"} or a plain value, not an arbitrary object"],"exampleFix":"// before\n{\"status\":\"已完结\"}\n// after\n{\"status\":\"finished\"}","handlingStrategy":"validation","validationCode":"boolean ok = EnumDict.find(MyEnum.class, rawValue).isPresent();\nif (!ok) throw new IllegalArgumentException(\"unknown dict value: \" + rawValue);","typeGuard":"static <E extends Enum<E> & EnumDict<?>> boolean isEnumDictValue(Class<E> type, Object v) {\n    return EnumDict.find(type, v).isPresent();\n}","tryCatchPattern":"try {\n    return JSON.parseObject(text, type);\n} catch (JSONException e) {\n    log.warn(\"unparseable enum value: {}\", text, e);\n    return null;\n}","preventionTips":["Keep enum values in sync with dictionary data in the database","Send plain values or {\"text\": ...} objects with valid text","Add unit tests deserializing every enum constant","Reject invalid dict values at the API boundary"],"tags":["json","deserialization","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8","analyzedAt":"2026-09-13T09:05:02.172Z","contentChangedAt":"2026-09-13T09:05:02.172Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}