Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

jackson convert a map to list of object

$
0
0

I have the below Sinister entity

@Document@Getter@Setter@ToString@AllArgsConstructor@NoArgsConstructor@Builder(toBuilder = true)@JsonInclude(JsonInclude.Include.NON_EMPTY)public class Sinister {    ....}public String on(FindSinister query) {    final Map<Object, Object> hashEntries = redisTemplate.opsForHash().entries(Sinister.class.getSimpleName());    final List<Object> allValuesFromHash = new ArrayList<>(hashEntries.values());    if (CollectionUtils.isNotEmpty(allValuesFromHash)) {        final JavaType targetType = objectMapper.getTypeFactory().constructCollectionType(List.class, Sinister.class);        final List<Sinister> sinisters = objectMapper.readValue(objectMapper.writeValueAsString(allValuesFromHash), targetType);    }    ....}

I have the above method when i get the list of entities from redis, the fuction entries return a Map<Object, Object>, when i tried to convert it to List of Sinister i have the below error:

    com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `Sinister` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('Sinister') at [Source: (StringReader); line: 1, column: 56495] (through reference chain: java.util.ArrayList[85])' and exception = 'null'java.lang.reflect.UndeclaredThrowableException

Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>