Mean value obtained through key, and will he converted to the corresponding type, now I have a data in redis, format for:
Here's the thing, I will he converted to one of my type, called AdminDetails, this class are defined as follows:
Run the code, some problems appear, look at the picture:
I use Object accept Object, because I am that a string of JSON format, he gave me type automatically converted to the LinkedHashMap, eventually leading to failure I conversion, but I actually incoming type AdminDetails
This type of format, how to correct the transformation, beg of bigwigs doubt!!!!!!!!!!!!!!!!!!!!
But beyond that, the get method can also operate a lot of other types, such as String, Map, etc.
By the way, I set the cache code is as follows:
CodePudding user response:
Using json utility classThe import net. Sf. Json. JSONArray;
The import net. Sf. Json. JSONObject;
CodePudding user response:
JsonObject cannot parse, he automatically transformed into LinkedHashMap, but I want to specify AdminDetails, cannot successfully parsedCodePudding user response:
Redis values is a deserialization process, he didn't know you are in the process is put into a bean type, endures redis is a serialization process, when I see you use the objectmapper, so the simplest you directly use the string to accept you to get the value, then objectmapper. ReadValue (STR, AdminDetail. Class) to fetch it, he will automatically help you deserialized into your AdminDetail objectCodePudding user response:
My way is directly to the result of strong to T, and then call the get method with AdminDetails directly accept there, but at least need to accept to use JSON. ToJSONString into String, again using JSON. ParseObject into AdminDetails, like this are still confused, I clearly deposit is AdminDetails the JSON data object, why not take out using direct assignment, for example: AdminDetails aaa=redisTemplate. Get (XXX) like this,CodePudding user response: