use of org.apache.logging.log4j.util.StringMap in project logging-log4j2 by apache.
the class ContextDataAttributeConverterTest method testConvertToDatabaseColumn02.
@Test
public void testConvertToDatabaseColumn02() {
final StringMap map = new SortedArrayStringMap();
map.putValue("someKey", "coolValue");
map.putValue("anotherKey", "testValue");
map.putValue("myKey", "yourValue");
assertEquals("The converted value is not correct.", map.toString(), this.converter.convertToDatabaseColumn(map));
}
use of org.apache.logging.log4j.util.StringMap in project logging-log4j2 by apache.
the class ContextDataJsonAttributeConverterTest method testConvert01.
@Test
public void testConvert01() {
final StringMap map = new SortedArrayStringMap();
map.putValue("test1", "another1");
map.putValue("key2", "value2");
final String converted = this.converter.convertToDatabaseColumn(map);
assertNotNull("The converted value should not be null.", converted);
final ReadOnlyStringMap reversed = this.converter.convertToEntityAttribute(converted);
assertNotNull("The reversed value should not be null.", reversed);
assertEquals("The reversed value is not correct.", map, reversed);
}
use of org.apache.logging.log4j.util.StringMap in project logging-log4j2 by apache.
the class MDCContextMap method getReadOnlyContextData.
@Override
public StringMap getReadOnlyContextData() {
final Map<String, String> copy = getCopy();
if (copy.isEmpty()) {
return EMPTY_CONTEXT_DATA;
}
final StringMap result = new SortedArrayStringMap();
for (final Entry<String, String> entry : copy.entrySet()) {
result.putValue(entry.getKey(), entry.getValue());
}
return result;
}
use of org.apache.logging.log4j.util.StringMap in project logging-log4j2 by apache.
the class ContextDataJsonAttributeConverter method convertToEntityAttribute.
@Override
public ReadOnlyStringMap convertToEntityAttribute(final String s) {
if (Strings.isEmpty(s)) {
return null;
}
try {
final StringMap result = ContextDataFactory.createContextData();
final ObjectNode root = (ObjectNode) OBJECT_MAPPER.readTree(s);
final Iterator<Map.Entry<String, JsonNode>> entries = root.fields();
while (entries.hasNext()) {
final Map.Entry<String, JsonNode> entry = entries.next();
// Don't know what to do with non-text values.
// Maybe users who need this need to provide custom converter?
final Object value = entry.getValue().textValue();
result.putValue(entry.getKey(), value);
}
return result;
} catch (final IOException e) {
throw new PersistenceException("Failed to convert JSON string to map.", e);
}
}
use of org.apache.logging.log4j.util.StringMap in project logging-log4j2 by apache.
the class MutableLogEventTest method createContextData.
private static StringMap createContextData() {
final StringMap result = new SortedArrayStringMap();
result.putValue("a", "1");
result.putValue("b", "2");
return result;
}
Aggregations