Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
webconsole-3.0.0
-
None
Description
Currently few plugins are making their own methods to convert an object (array) to string. And usually uses different approaches for converting the arrays:
#1 The following methods will convert array to string like "1, 2, 3". They use StringBuffer and append elements one by one.
ServicesServlet.propertyAsString()
ConfigurationRendere.asString()
#2 Another approach that is used, converts the array to List, and then toString() which returns "[1, 2, 3]"
ComponentConfigurationPrinter.listProperties()
ComponentServlet.listProperties()
#3 in event plugin the code from the method below prints "[1, 2, 3]" but uses approach similar to #1
PluginServlet.eventJson
The smaller problem is that we have duplicate code. The bigger problem is that the code ... will not work correctly, if the array is from primitive types (see https://issues.apache.org/jira/browse/FELIX-2142).
So my proposal is to add a new utility method,
WebConsoleUtil.toString(Object val, boolean addBracesIfArray);
The other option is to remove addBracesIfArray and always assume, that if it is array, the value is wrapped with [] braces.
–
WDYT?