@SuppressWarnings("unchecked") @Test public void multipleMdcFields() throws Exception { StringBuilder sb = new StringBuilder(); @SuppressWarnings("serial") Map<String, String> mdcFields = new HashMap<String, String>() { { put(CUSTOM_KEY_1, CUSTOM_VALUE_1); put(UNREGISTERED_KEY, UNREGISTERED_VALUE); put(CUSTOM_KEY_0, CUSTOM_VALUE_0); } }; converter.convert(sb, mdcFields); assertThat(unmarshalCustomFields(sb), containsInAnyOrder(hasCustomField(CUSTOM_KEY_0, CUSTOM_VALUE_0, 0), hasCustomField(CUSTOM_KEY_1, CUSTOM_VALUE_1, 1))); }
public void convert(StringBuilder appendTo, Map<String, String> mdcPropertiesMap, Object... arguments) { if (customFieldKeyNames.isEmpty()) { return; } Map<String, CustomField> customFields = getRegisteredCustomFields(arguments); Map<String, String> mdcCustomFields = getRegisteredMdcCustomFields(mdcPropertiesMap); if (!customFields.isEmpty() || !mdcCustomFields.isEmpty()) { try { ArrayComposer<ObjectComposer<JSONComposer<String>>> oc = startJson(appendTo); addCustomFields(oc, customFields, mdcCustomFields); finishJson(oc, appendTo); } catch (Exception ex) { LoggerFactory.getLogger(DefaultCustomFieldsConverter.class).error("Conversion failed ", ex); } } }
DefaultCustomFieldsConverter { public void convert(StringBuilder appendTo, Map<String, String> mdcPropertiesMap, Object... arguments) { if (customFieldKeyNames.isEmpty()) { return; } Map<String, CustomField> customFields = getRegisteredCustomFields(arguments); Map<String, String> mdcCustomFields = getRegisteredMdcCustomFields(mdcPropertiesMap); if (!customFields.isEmpty() || !mdcCustomFields.isEmpty()) { try { ArrayComposer<ObjectComposer<JSONComposer<String>>> oc = startJson(appendTo); addCustomFields(oc, customFields, mdcCustomFields); finishJson(oc, appendTo); } catch (Exception ex) { LoggerFactory.getLogger(DefaultCustomFieldsConverter.class).error("Conversion failed ", ex); } } } }
DefaultCustomFieldsConverter { public void convert(StringBuilder appendTo, Map<String, String> mdcPropertiesMap, Object... arguments) { if (customFieldKeyNames.isEmpty()) { return; } Map<String, CustomField> customFields = getRegisteredCustomFields(arguments); Map<String, String> mdcCustomFields = getRegisteredMdcCustomFields(mdcPropertiesMap); if (!customFields.isEmpty() || !mdcCustomFields.isEmpty()) { try { ArrayComposer<ObjectComposer<JSONComposer<String>>> oc = startJson(appendTo); addCustomFields(oc, customFields, mdcCustomFields); finishJson(oc, appendTo); } catch (Exception ex) { LoggerFactory.getLogger(DefaultCustomFieldsConverter.class).error("Conversion failed ", ex); } } }  }
DefaultCustomFieldsConverter { public void convert(StringBuilder appendTo, Map<String, String> mdcPropertiesMap, Object... arguments) { if (customFieldKeyNames.isEmpty()) { return; } Map<String, CustomField> customFields = getRegisteredCustomFields(arguments); Map<String, String> mdcCustomFields = getRegisteredMdcCustomFields(mdcPropertiesMap); if (!customFields.isEmpty() || !mdcCustomFields.isEmpty()) { try { ArrayComposer<ObjectComposer<JSONComposer<String>>> oc = startJson(appendTo); addCustomFields(oc, customFields, mdcCustomFields); finishJson(oc, appendTo); } catch (Exception ex) { LoggerFactory.getLogger(DefaultCustomFieldsConverter.class).error("Conversion failed ", ex); } } }  void setFieldName(String fieldName); void setCustomFieldKeyNames(List<String> customFieldKeyNames); void convert(StringBuilder appendTo, Map<String, String> mdcPropertiesMap, Object... arguments); }
DefaultCustomFieldsConverter { public void convert(StringBuilder appendTo, Map<String, String> mdcPropertiesMap, Object... arguments) { if (customFieldKeyNames.isEmpty()) { return; } Map<String, CustomField> customFields = getRegisteredCustomFields(arguments); Map<String, String> mdcCustomFields = getRegisteredMdcCustomFields(mdcPropertiesMap); if (!customFields.isEmpty() || !mdcCustomFields.isEmpty()) { try { ArrayComposer<ObjectComposer<JSONComposer<String>>> oc = startJson(appendTo); addCustomFields(oc, customFields, mdcCustomFields); finishJson(oc, appendTo); } catch (Exception ex) { LoggerFactory.getLogger(DefaultCustomFieldsConverter.class).error("Conversion failed ", ex); } } }  void setFieldName(String fieldName); void setCustomFieldKeyNames(List<String> customFieldKeyNames); void convert(StringBuilder appendTo, Map<String, String> mdcPropertiesMap, Object... arguments);  }