ec75f78468656027a4af1b50192f3ef9ceb1d2dd
[ccsdk/features.git] /
1 package org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize;
2
3 import com.fasterxml.jackson.core.JsonParser;
4 import com.fasterxml.jackson.core.JsonProcessingException;
5 import com.fasterxml.jackson.databind.DeserializationContext;
6 import com.fasterxml.jackson.databind.JsonDeserializer;
7 import com.fasterxml.jackson.databind.type.CollectionLikeType;
8 import java.io.IOException;
9 import java.util.HashSet;
10 import java.util.List;
11 import java.util.Set;
12
13 import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper;
14
15 public class SetDeserializer<V>
16         extends JsonDeserializer<Set<V>> {
17
18     private final Class<V> clazz;
19     private final YangToolsMapper mapper;
20
21     public SetDeserializer(Class<V> clazz) {
22         super();
23         this.clazz = clazz;
24         this.mapper = new YangToolsMapper();
25     }
26
27     @Override
28     public Set<V> deserialize(JsonParser p, DeserializationContext ctxt)
29             throws IOException, JsonProcessingException {
30         CollectionLikeType type = ctxt.getTypeFactory().constructCollectionType(Set.class, clazz);
31         List<V> list = mapper.readValue(p, type);
32         return new HashSet<>(list);
33     }
34
35 }