Skip to content

Commit

Permalink
fix: repository updateField ignores registered Gson TypeAdapters (res…
Browse files Browse the repository at this point in the history
…olves gh-284)
  • Loading branch information
bsbodden committed Jun 24, 2023
1 parent 2d60af4 commit 1288ece
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void set(K key, Object object) {

@Override
public void set(K key, Object object, Path path) {
client.clientForJSON().jsonSet(key.toString(), path, object);
client.clientForJSON().jsonSetWithPlainString(key.toString(), path, builder.gson().toJson(object));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import redis.clients.jedis.json.Path;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand All @@ -35,6 +36,9 @@ class BasicRedisDocumentMappingTest extends AbstractBaseDocumentTest {
@Autowired
DocWithEnumRepository docWithEnumRepository;

@Autowired
SomeDocumentRepository someDocumentRepository;

@BeforeEach
void cleanUp() {
flushSearchIndexFor(Company.class);
Expand Down Expand Up @@ -117,6 +121,18 @@ void testUpdateSingleField() {
assertThat(maybeRedis).isPresent().map(Company::getName).contains("Redis");
}

@Test
void testUpdateLocalDateTimeField() {
var now = LocalDateTime.now();
SomeDocument docWithDateTime = new SomeDocument();
docWithDateTime.setDocumentCreationDate(now);
docWithDateTime = someDocumentRepository.save(docWithDateTime);

someDocumentRepository.updateField(docWithDateTime, SomeDocument$.DOCUMENT_CREATION_DATE, now.minusDays(5));

assertThat(someDocumentRepository.findById(docWithDateTime.getId()).get().getDocumentCreationDate()).isEqualToIgnoringNanos(now.minusDays(5));
}

@Test
void testAuditAnnotations() {
Company redis = repository.save(
Expand Down

0 comments on commit 1288ece

Please sign in to comment.