This repository was archived by the owner on Apr 4, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed
main/java/org/springframework/session/data/mongo
test/java/org/springframework/session/data/mongo Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -111,8 +111,10 @@ protected DBObject convert(MongoSession source) {
111
111
112
112
try {
113
113
DBObject dbSession = (DBObject ) JSON .parse (this .objectMapper .writeValueAsString (source ));
114
- dbSession .put (EXPIRE_AT_FIELD_NAME , source .getExpireAt ());
114
+
115
+ // Override default serialization with proper values.
115
116
dbSession .put (PRINCIPAL_FIELD_NAME , extractPrincipal (source ));
117
+ dbSession .put (EXPIRE_AT_FIELD_NAME , source .getExpireAt ());
116
118
return dbSession ;
117
119
} catch (JsonProcessingException e ) {
118
120
throw new IllegalStateException ("Cannot convert MongoExpiringSession" , e );
@@ -123,8 +125,7 @@ protected DBObject convert(MongoSession source) {
123
125
@ Nullable
124
126
protected MongoSession convert (Document source ) {
125
127
126
- Date expireAt = source .getDate (EXPIRE_AT_FIELD_NAME );
127
- source .remove (EXPIRE_AT_FIELD_NAME );
128
+ Date expireAt = (Date ) source .remove (EXPIRE_AT_FIELD_NAME );
128
129
String json = source .toJson (JsonWriterSettings .builder ().outputMode (JsonMode .RELAXED ).build ());
129
130
130
131
try {
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ AbstractMongoSessionConverter getMongoSessionConverter() {
44
44
}
45
45
46
46
@ Test
47
- public void shouldSaveIdField () throws Exception {
47
+ public void shouldSaveIdField () {
48
48
49
49
// given
50
50
MongoSession session = new MongoSession ();
@@ -109,16 +109,19 @@ public void shouldLoadExpireAtFromDocument() {
109
109
110
110
// given
111
111
Date now = new Date ();
112
- HashMap data = new HashMap ();
112
+ HashMap <String , Object > data = new HashMap <>();
113
+
113
114
data .put ("expireAt" , now );
114
115
data .put ("@class" , MongoSession .class .getName ());
115
116
data .put ("_id" , new ObjectId ().toString ());
117
+
116
118
Document document = new Document (data );
117
119
118
120
// when
119
121
MongoSession convertedSession = this .mongoSessionConverter .convert (document );
120
122
121
123
// then
124
+ assertThat (convertedSession ).isNotNull ();
122
125
assertThat (convertedSession .getExpireAt ()).isEqualTo (now );
123
126
}
124
127
You can’t perform that action at this time.
0 commit comments