formatAsString
Versionshinweise | 24.1 |
---|
Code
String formatAsString(List<Object> myList oder Map<String, Object> myMap, int indent, StringFormatType formatType, int maxIndent)
Beschreibung
Erstellt ein neues Antwort-Objekt für das Mocken von REST-Aufrufen.
Parameter
myList
odermyMap
Die Liste oder Map die in einen String umgewandelt werden soll.indent
- optional Die initiale Einrückung, Standard 1formatType
- optional Der genutzte Format-Typ, Standard ScriptUtils.FORMAT_TABSmaxIndent
- optional Die maximale Einrückung für enthaltene Listen und Maps, abgeschnittene Zweige werden mit (...) dargestellt, Standard 10
Rückgabe
Das als String dargestellte Liste oder Map.
Beispiele
List<Object> lists = new ArrayList<>();
lists.add("Value1");
lists.add(1);
lists.add(null);
Map<String, Object> map = new HashMap<>();
map.put("map1_param1", "mapVal1");
map.put("map1_param2", 2d);
map.put("map1_param3", null);
map.put("map1_param4", list);
ScriptUtils.error("formatted List default [" + ScriptUtils.formatAsString(lists) + "]");
// Examples using the optional formatType parameter
ScriptUtils.error("formatted Map tabs [" + ScriptUtils.formatAsString(map, ScriptUtils.FORMAT_TABS) + "]");
ScriptUtils.error("formatted Map spaces [" + ScriptUtils.formatAsString(map, ScriptUtils.FORMAT_SPACE) + "]");
ScriptUtils.error("formatted Map html [" + ScriptUtils.formatAsString(map, ScriptUtils.FORMAT_HTML) + "]");
ScriptUtils.error("formatted Map flat list [" + ScriptUtils.formatAsString(map, ScriptUtils.FORMAT_FLAT_LIST) + "]");
ScriptUtils.error("formatted Map flat list with index [" + ScriptUtils.formatAsString(map, ScriptUtils.FORMAT_FLAT_LIST_INDEX) + "]");
ScriptUtils.error("formatted Map flat list and map [" + ScriptUtils.formatAsString(map, ScriptUtils.FORMAT_FLAT_LIST_MAP) + "]");
lists.add(map); // recursvie call, which is "stopped" by maxIndent
// Example using all optional formatType parameter
ScriptUtils.error("formatted Map all parameter [" + ScriptUtils.formatAsString(map, 0, ScriptUtils.FORMAT_TABS, 3) + "]");
Die Ergebnisse im Log sehen dann in etwa so aus (Zeitstempel wurden entfernt)
[ERROR] formatted List default [
0: Value1,
1: 1,
2: NULL value]
[ERROR] formatted Map tabs [
map1_param2: 2.0
map1_param1: mapVal1
map1_param4:
0: Value1,
1: 1,
2: NULL value
map1_param3: NULL value]
[ERROR] formatted Map spaces [
map1_param2: 2.0
map1_param1: mapVal1
map1_param4:
0: Value1,
1: 1,
2: NULL value
map1_param3: NULL value]
[ERROR] formatted Map html [<br> map1_param2: 2.0,<br> map1_param1: mapVal1,<br> map1_param4: <br> 0: Value1<br> 1: 1<br> 2: NULL value,<br> map1_param3: NULL value]
[ERROR] formatted Map flat list [
map1_param2: 2.0
map1_param1: mapVal1
map1_param4: Value1, 1, NULL value
map1_param3: NULL value]
[ERROR] formatted Map flat list with index [
map1_param2: 2.0
map1_param1: mapVal1
map1_param4: 0: Value1, 1: 1, 2: NULL value
map1_param3: NULL value]
[ERROR] formatted Map flat list and map [map1_param2: 2.0, map1_param1: mapVal1, map1_param4: Value1, 1, NULL value, map1_param3: NULL value]
[ERROR] formatted Map all parameter [
map1_param2: 2.0
map1_param1: mapVal1
map1_param4:
0: Value1,
1: 1,
2: NULL value,
3:
map1_param2: 2.0
map1_param1: mapVal1
map1_param4:
0: Value1,
1: 1,
2: NULL value,
3:
(...)
map1_param3: NULL value
map1_param3: NULL value]