A
A
askar982021-04-10 15:14:30
Java
askar98, 2021-04-10 15:14:30

Spring boot cache return list of objects with null?

Hello! The first time I get data from the database, everything works fine, but when I get null attribute values ​​from the cache
``` code

@Cacheable(value = "userStore)
    public List<UserDto> getAllUsers(String typeCode) {
        return userRepo.findAllByType(typeCode).stream().map(this::mapEntityToDto).collect(Collectors.toList());
    }

Cache response:
[
  {
    "login": null,
    "name": null
  },
  {
    "login": null,
    "name": null
  },
  {
    "login": null,
    "name": null
  }
]

The value of the key in radish is something like this:
��srjava.util.ArrayListx����a�......

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
askar98, 2021-04-11
@askar98

Returned null fields, because it inherits these fields from the parent, and it was not serializable.
If your object is serializable and extends an object that is not serializable, then instead of the NotSerializeException which would be useful, the fields of the parent object are only initialized which is why you have them as nulls.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question