Skip to main content
Skip table of contents

formatAsString

Versionshinweise

24.1

Code

GROOVY
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 oder myMap Die Liste oder Map die in einen String umgewandelt werden soll.

  • indent - optional Die initiale Einrückung, Standard 1

  • formatType - optional Der genutzte Format-Typ, Standard ScriptUtils.FORMAT_TABS

  • maxIndent - 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

GROOVY
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>&nbsp;&nbsp;&nbsp;map1_param2:&nbsp;2.0,<br>&nbsp;&nbsp;&nbsp;map1_param1:&nbsp;mapVal1,<br>&nbsp;&nbsp;&nbsp;map1_param4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0: Value1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1: 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2: NULL value,<br>&nbsp;&nbsp;&nbsp;map1_param3:&nbsp;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]  

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.