Polishing.

This commit is contained in:
Greg Turnquist
2019-03-15 11:19:33 -05:00
parent 82cf365ba7
commit 54fa3f9d58
2 changed files with 9 additions and 5 deletions

View File

@@ -111,8 +111,10 @@ public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter
try {
DBObject dbSession = (DBObject) JSON.parse(this.objectMapper.writeValueAsString(source));
dbSession.put(EXPIRE_AT_FIELD_NAME, source.getExpireAt());
// Override default serialization with proper values.
dbSession.put(PRINCIPAL_FIELD_NAME, extractPrincipal(source));
dbSession.put(EXPIRE_AT_FIELD_NAME, source.getExpireAt());
return dbSession;
} catch (JsonProcessingException e) {
throw new IllegalStateException("Cannot convert MongoExpiringSession", e);
@@ -123,8 +125,7 @@ public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter
@Nullable
protected MongoSession convert(Document source) {
Date expireAt = source.getDate(EXPIRE_AT_FIELD_NAME);
source.remove(EXPIRE_AT_FIELD_NAME);
Date expireAt = (Date) source.remove(EXPIRE_AT_FIELD_NAME);
String json = source.toJson(JsonWriterSettings.builder().outputMode(JsonMode.RELAXED).build());
try {

View File

@@ -44,7 +44,7 @@ public class JacksonMongoSessionConverterTest extends AbstractMongoSessionConver
}
@Test
public void shouldSaveIdField() throws Exception {
public void shouldSaveIdField() {
// given
MongoSession session = new MongoSession();
@@ -109,16 +109,19 @@ public class JacksonMongoSessionConverterTest extends AbstractMongoSessionConver
// given
Date now = new Date();
HashMap data = new HashMap();
HashMap<String, Object> data = new HashMap<>();
data.put("expireAt", now);
data.put("@class", MongoSession.class.getName());
data.put("_id", new ObjectId().toString());
Document document = new Document(data);
// when
MongoSession convertedSession = this.mongoSessionConverter.convert(document);
// then
assertThat(convertedSession).isNotNull();
assertThat(convertedSession.getExpireAt()).isEqualTo(now);
}