SoFunction
Updated on 2025-03-03

Redis error UnrecognizedPropertyException: Unrecognized field problem

1. Phenomenon

Spring Boot accesses Redis, and an error occurred when fetching the object

Error message:

Caused by: : Unrecognized field "headPart" 
    at (:61)
    at (:823)
    at (:1153)
    at (:1589)
    at (:1567)
    at (:294)
    at (:151)
    at ._deserialize(:116)
    at (:71)
    at $(:712)
    at (:68)
    at ._readMapAndClose(:4013)
    at (:3129)
    at .(:73)
    ... 39 common frames omitted

2. Troubleshooting

At first I thought I forgot to writeimplements Serializable, this is not the problem after checking.

Then I thought I forgot to write the get set method, and it was not the case after checking it.

Finally, I found the details:

Unrecognized field "headPart"

That is to say, the attribute headPart cannot be recognized

Suddenly I realized that I wrote a method getHeadPart, but it does not have the headPart attribute

3. Solve

Change getHeadPart to makeHeadPart...

Serialization tools like jackson rely on reflection to identify method properties. Methods starting with get are easy to mislead serialization tools.

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.