1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.metadata.jaxbadapters;
17
18 import javax.xml.bind.annotation.adapters.XmlAdapter;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24
25
26
27 public class StringMapAdapter extends XmlAdapter<StringMap, Map<String, List<String>>> {
28
29 @Override
30 public StringMap marshal(Map<String, List<String>> v) throws Exception {
31 if (v == null) {
32 return null;
33 }
34
35 StringMap result = new StringMap();
36 result.entries = new ArrayList<>();
37 for (Map.Entry<String, List<String>> entry : v.entrySet()) {
38 StringMapEntry extra = new StringMapEntry();
39 extra.setKey(entry.getKey());
40 extra.setValues(new ArrayList<>());
41 extra.getValues().addAll(entry.getValue());
42 result.entries.add(extra);
43 }
44
45 return result;
46 }
47
48
49 @Override
50 public Map<String, List<String>> unmarshal(StringMap v) throws Exception {
51 if ((v == null) || (v.entries == null)) {
52 return null;
53 }
54
55 HashMap<String, List<String>> result = new HashMap<>();
56 for (StringMapEntry extra : v.entries) {
57 result.put(extra.getKey(), extra.getValues());
58 }
59 return result;
60 }
61
62 }