Home > Back-end >  About interface in Java serialization and deserialization problem bosses to reassure [o]
About interface in Java serialization and deserialization problem bosses to reassure [o]

Time:10-29

The younger brother in a recent study spring oauth2
Token is now using redis cache, and then find another check_token interface, each time to get the database client information, in order to facilitate management of client information, the data must be need to put the unified management of the database, but this time to get feeling is not very completed,

Last night, wanted to think, decided to rewrite JdbcClientDetailsService this implementation, add its own cache for business, so have the following code (the product comforms to the drawing I turn Java, c #),
 
/* *
* access to the cache
*
* @ return client information
*/
Private List GetCache () {
List ClientDetails=(List) RedisUtil. Get (JdbcClientDetailsConstant. JDBC_CLIENT_DETAILS_KEY);
Return clientDetails;
}

/* *
* reset redis cache
*
* @ return client information
*/
Private List SetCache () {
List ClientDetails=super. ListClientDetails ();
RedisUtil. Set (JdbcClientDetailsConstant JDBC_CLIENT_DETAILS_KEY, clientDetails);
Return clientDetails;
}


My idea is a major rewrite loadClientByClientId the interface to the information of the client, not all client information in the cache will query the database, and save the redis cache, without the second has a cache to check the database, the only need to do is ensure that client information is added to reset the cache deletion,

Idea is a good thing, such as code spluttered pa to knock out, for the first time access token is no problem, then try a second time will be an error

 
Com. Alibaba. Fastjson. JSONException: autoType is not support. Org. Springframework. Security. Oauth2. Provider. Client. BaseClientDetails


And point into ClientDetails, found that the interface is defined,,,
 
Package org. Springframework. Security. Oauth2. The provider;

Import the Java. IO. Serializable.
Import the Java. Util. Collection;
Import the Java. Util. The Map;
Import the Java. Util. Set;

The import org. Springframework. Security. Core. GrantedAuthority;

/* *
* the Client details for request 2
*
* @ author Ryan Heaton
*/
Public interface ClientDetails extends the Serializable {
.
}

In previous studies, flowable process engine when I was found to have this kind of usage, the use interface instead of entities in the younger brother is not understand, baidu, no reason, also,

Now stuck in here, want to write a entity inheritance ClientDetails, but that is about to rewrite all of his method,,,

For bosses to reassure

CodePudding user response:

From the point of your exception, is com. Alibaba. Fastjson. JSONException, I'm thinking, why is this? Because your post code, can't see information about fastjson?
Let me guess, you read again and storage, storage time is an object directly, is that I want to on your method of internal storage with fastjson transformed into string, and then take it by the string when converted into objects,

If so, explain why not first, by the string to the object, if is a POJO, he must go, but you gave it to a interface, fastjson certainly don't know what you want is which implementation class, certainly not,

So how to solve this problem?
With fastjson certainly not, do you think the somebody else all implements Serializable support serialization, so you just put the object serialization into object flow, then transform into a byte array, and then stored in redis, use redis store a byte array of the way to go, and then out bytes of data, then converted into object flow, have to do is to convert objects,

This is a common solution to redis store objects,
Sequence with the sequence about Java code, a lot of online, search the line,
  • Related