@Test public void properlyEscapesKeys() throws Exception { StringBuilder sb = new StringBuilder(); @SuppressWarnings("serial") Map<String, String> explicitFields = new HashMap<String, String>() { { put("explicit" + HACK_ATTEMPT, "explicit value"); } }; MDC.put("mdc" + HACK_ATTEMPT, "mdc value"); converter.convert(sb, explicitFields); assertThat(unmarshal(sb), allOf(hasEntry("mdc" + HACK_ATTEMPT, "mdc value"), hasEntry("explicit" + HACK_ATTEMPT, "explicit value"))); }
public void convert(StringBuilder appendTo, Map<String, String> eventProperties) { Map<String, String> properties = mergeContextMaps(eventProperties); if (properties != null && !properties.isEmpty()) { try { ObjectComposer<JSONComposer<String>> oc = JSON.std.composeString().startObject(); for (Entry<String, String> p: properties.entrySet()) { if (!exclusions.contains(p.getKey())) { oc.put(p.getKey(), p.getValue()); } } String result = oc.end().finish().trim(); appendTo.append(result.substring(1, result.length() - 1)); } catch (Exception ex) { LoggerFactory.getLogger(DefaultPropertiesConverter.class).error("Conversion failed ", ex); } } }
DefaultPropertiesConverter { public void convert(StringBuilder appendTo, Map<String, String> eventProperties) { Map<String, String> properties = mergeContextMaps(eventProperties); if (properties != null && !properties.isEmpty()) { try { ObjectComposer<JSONComposer<String>> oc = JSON.std.composeString().startObject(); for (Entry<String, String> p: properties.entrySet()) { if (!exclusions.contains(p.getKey())) { oc.put(p.getKey(), p.getValue()); } } String result = oc.end().finish().trim(); appendTo.append(result.substring(1, result.length() - 1)); } catch (Exception ex) { LoggerFactory.getLogger(DefaultPropertiesConverter.class).error("Conversion failed ", ex); } } } }
DefaultPropertiesConverter { public void convert(StringBuilder appendTo, Map<String, String> eventProperties) { Map<String, String> properties = mergeContextMaps(eventProperties); if (properties != null && !properties.isEmpty()) { try { ObjectComposer<JSONComposer<String>> oc = JSON.std.composeString().startObject(); for (Entry<String, String> p: properties.entrySet()) { if (!exclusions.contains(p.getKey())) { oc.put(p.getKey(), p.getValue()); } } String result = oc.end().finish().trim(); appendTo.append(result.substring(1, result.length() - 1)); } catch (Exception ex) { LoggerFactory.getLogger(DefaultPropertiesConverter.class).error("Conversion failed ", ex); } } } DefaultPropertiesConverter(); }
DefaultPropertiesConverter { public void convert(StringBuilder appendTo, Map<String, String> eventProperties) { Map<String, String> properties = mergeContextMaps(eventProperties); if (properties != null && !properties.isEmpty()) { try { ObjectComposer<JSONComposer<String>> oc = JSON.std.composeString().startObject(); for (Entry<String, String> p: properties.entrySet()) { if (!exclusions.contains(p.getKey())) { oc.put(p.getKey(), p.getValue()); } } String result = oc.end().finish().trim(); appendTo.append(result.substring(1, result.length() - 1)); } catch (Exception ex) { LoggerFactory.getLogger(DefaultPropertiesConverter.class).error("Conversion failed ", ex); } } } DefaultPropertiesConverter(); void setExclusions(List<String> exclusionList); void convert(StringBuilder appendTo, Map<String, String> eventProperties); }
DefaultPropertiesConverter { public void convert(StringBuilder appendTo, Map<String, String> eventProperties) { Map<String, String> properties = mergeContextMaps(eventProperties); if (properties != null && !properties.isEmpty()) { try { ObjectComposer<JSONComposer<String>> oc = JSON.std.composeString().startObject(); for (Entry<String, String> p: properties.entrySet()) { if (!exclusions.contains(p.getKey())) { oc.put(p.getKey(), p.getValue()); } } String result = oc.end().finish().trim(); appendTo.append(result.substring(1, result.length() - 1)); } catch (Exception ex) { LoggerFactory.getLogger(DefaultPropertiesConverter.class).error("Conversion failed ", ex); } } } DefaultPropertiesConverter(); void setExclusions(List<String> exclusionList); void convert(StringBuilder appendTo, Map<String, String> eventProperties);  }