{"record":{"id":"779760419e063947","repo":"FasterXML/jackson-databind","slug":"cannot-update-map-entry-values-779760","errorCode":null,"errorMessage":"Cannot update `Map.Entry` values","messagePattern":"Cannot update `Map\\.Entry` values","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/deser/jdk/MapEntryDeserializer.java","lineNumber":522,"sourceCode":"                }\n\n                t = p.nextToken(); // move to next property or END_OBJECT\n            }\n\n            if (t != JsonToken.END_OBJECT) {\n                ctxt.reportInputMismatch(this,\n                        \"Problem deserializing `Map.Entry`; unexpected content after Object value: \"\n                                +JsonToken.valueDescFor(t));\n            }\n\n            return new AbstractMap.SimpleEntry<>(key, value);\n        }\n        \n        @Override\n        public Map.Entry<Object,Object> deserialize(JsonParser p, DeserializationContext ctxt,\n                Map.Entry<Object,Object> result) throws JacksonException\n        {\n            throw new IllegalStateException(\"Cannot update `Map.Entry` values\");\n        }\n\n        @Override\n        public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,\n                TypeDeserializer typeDeserializer)\n            throws JacksonException\n        {\n            // In future could check current token... for now this should be enough:\n            return typeDeserializer.deserializeTypedFromObject(p, ctxt);\n        }\n\n        // Copied from `ContainerDeserializerBase`\n        protected <BOGUS> BOGUS wrapAndThrow(DeserializationContext ctxt,\n                Throwable t, Object ref, String key) throws JacksonException\n        {\n            while (t instanceof InvocationTargetException && t.getCause() != null) {\n                t = t.getCause();\n            }","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/deser/jdk/MapEntryDeserializer.java#L504-L540","documentation":"Thrown by POJOWrappedDeserializer.deserialize(JsonParser, DeserializationContext, Map.Entry result) — the update-in-place overload on the POJO-wrapped variant of MapEntryDeserializer. This variant deserializes Map.Entry from a JSON object with 'key' and 'value' fields (as opposed to a single-entry object). Like the base class, Map.Entry cannot be updated in-place, so it throws IllegalStateException with the message formatted with backtick-quoted Map.Entry.","triggerScenarios":"Calling mapper.readerForUpdating(existingEntry).readValue(json) where the entry uses the POJO-wrapped format (JSON like {\"key\":...,\"value\":...}). Any update-path that routes through POJOWrappedDeserializer for a Map.Entry type. Using ObjectReader.updateValue() on a Map.Entry configured for POJO-wrapped shape.","commonSituations":"Configuring @JsonFormat(shape=ANY) or ACCEPT_CASE_INSENSITIVE_PROPERTIES on a Map.Entry type and then attempting update. Using JsonFormat.Value for Map.Entry to force POJO-wrapped format. Round-tripping through update APIs after switching the entry deserialization format.","solutions":["Do not use update-in-place APIs with Map.Entry — deserialize fresh each time.","If POJO-wrapped format is needed, read into a new Map.Entry rather than updating.","Use a custom POJO with 'key' and 'value' fields if you need both POJO format and update semantics.","Avoid the three-argument deserialize overload for any Map.Entry variant."],"exampleFix":"// before: update on POJO-wrapped entry\nmapper.readerForUpdating(oldEntry).readValue(\"{\\\"key\\\":1,\\\"value\\\":2}\");\n// after: fresh deserialize\nMap.Entry<Integer,Integer> e = mapper.readValue(\"{\\\"key\\\":1,\\\"value\\\":2}\",\n    new TypeReference<Map.Entry<Integer,Integer>>() {});","handlingStrategy":"try-catch","validationCode":"// Detect POJO-wrapped Map.Entry and avoid update paths\nif (Map.Entry.class.isAssignableFrom(targetType)) {\n    // POJOWrappedDeserializer also rejects updates\n    throw new UnsupportedOperationException(\n        \"Cannot update Map.Entry (POJO-wrapped) — deserialize fresh\");\n}","typeGuard":"static boolean isUpdatable(Class<?> type) {\n    return !Map.Entry.class.isAssignableFrom(type);\n}","tryCatchPattern":"try {\n    mapper.readerForUpdating(oldEntry).readValue(\"{\\\"key\\\":1,\\\"value\\\":2}\");\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Cannot update `Map.Entry`\")) {\n        entry = mapper.readValue(json, entryTypeRef);\n    }\n}","preventionTips":["Never use update-in-place APIs with Map.Entry regardless of deserialization format.","Always create fresh Map.Entry instances from JSON.","Use mutable wrapper POJOs if update semantics are required."],"tags":["jackson","deserialization","map-entry","update-in-place","pojo-wrapped","immutable"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}