static Map<Keyword, Object> toKeywordMap(Event event) { Map<String, Object> rawStringMap = OBJECT_MAPPER.convertValue(event, new TypeReference<Map<String, ?>>() {}); return EntryStream.of(rawStringMap) .filterValues(Objects::nonNull) .mapKeys(Keyword::intern) .toMap(); }
static Event fromKeywordMap(Map<Keyword, ?> map) { Map<Keyword, ?> encodedMap = EventUtils.encodeNemesis(map); Map<String, Object> convertedMap = new HashMap<>(); EntryStream.of(encodedMap) .mapKeys(Keyword::getName) .mapValues(value -> value != null && value instanceof Keyword ? ((Keyword) value).getName() : value) .forKeyValue(convertedMap::put); return OBJECT_MAPPER.convertValue(convertedMap, Event.class); }
private static List<Map<Keyword, ?>> getClojureMapFromFile(String resourcePath) throws IOException { List<Map<String, ?>> allEvents = new ObjectMapper().readValue(Resources.getResource(resourcePath), new TypeReference<List<Map<String, ?>>>() {}); return allEvents.stream() .map(singleEvent -> { Map<Keyword, Object> convertedEvent = new HashMap<>(); EntryStream.of(singleEvent) .mapKeys(Keyword::intern) .mapValues(value -> value instanceof String ? Keyword.intern((String) value) : value) .forKeyValue(convertedEvent::put); return convertedEvent; }) .collect(Collectors.toList()); } }