View Javadoc

1   package com.atlassian.messagequeue.internal.lifecycle;
2   
3   import org.codehaus.jackson.map.ObjectMapper;
4   
5   import java.io.IOException;
6   import java.util.Optional;
7   
8   /**
9    * {@inheritDoc}
10   */
11  public class JacksonNotificationDeserializer implements NotificationDeserializer {
12      private final ObjectMapper objectMapper;
13  
14      public JacksonNotificationDeserializer() {
15          objectMapper = new ObjectMapper();
16      }
17  
18      @Override
19      public <T> Optional<T> deserialize(String string, Class<T> notificationType) {
20          if (string == null) {
21              return Optional.empty();
22          }
23  
24          try {
25              return Optional.ofNullable(objectMapper.readValue(string, notificationType));
26          } catch (IOException e) {
27              return Optional.empty();
28          }
29      }
30  }