serialize a List (as Array)

@param name
@param list List to serialize
@param sb
@param done
@return serialized list
@throws ConverterException
179846
private void _serializeList(String name, List list, StringBuilder sb, Set<Object> done) throws ConverterException {

	if (useShortcuts) sb.append("[];");
	else sb.append("new Array();");

	ListIterator it = list.listIterator();
	int index = -1;
	while (it.hasNext()) {
	    // if(index!=-1)sb.append(",");
	    index = it.nextIndex();
	    sb.append(name + "[" + index + "]=");
	    _serialize(name + "[" + index + "]", it.next(), sb, done);
	    // sb.append(";");
	}
    }
74328
@SuppressWarnings("unchecked")
	private void mergeNamedList(ShardRequest sreq, NamedList<Object> mtasResponse, String key,
			Integer preferredPurpose) {
		// create new response for key
		NamedList<Object> mtasListResponse;
		Object o = mtasResponse.get(key);
		if (o instanceof NamedList) {
			mtasListResponse = (NamedList<Object>) o;
		} else {
			mtasListResponse = new SimpleOrderedMap<>();
			mtasResponse.removeAll(key);
			mtasResponse.add(key, mtasListResponse);
		}
		// collect responses for each shard
		HashMap<String, NamedList<Object>> mtasListShardResponses = new HashMap<>();
		for (ShardResponse response : sreq.responses) {
			// only continue if new shard or preferred purpose
			if (mtasListShardResponses.containsKey(response.getShard())
					&& ((preferredPurpose == null) || (sreq.purpose != preferredPurpose))) {
				break;
			}
			// update
			try {
				NamedList<Object> result = response.getSolrResponse().getResponse();
				NamedList<Object> data = (NamedList<Object>) result.findRecursive("mtas", key);
				if (data != null) {
					mtasListShardResponses.put(response.getShard(), MtasSolrResultUtil.decode(data));
				}
			} catch (ClassCastException e) {
				log.debug(e);
			}
		}
		try {
			for (NamedList<Object> mtasListShardResponse : mtasListShardResponses.values()) {
				mergeResponsesNamedList(mtasListResponse, mtasListShardResponse);
			}
		} catch (IOException e) {
			log.error(e);
		}
	}
727625
public static String listToJson(List<?> list) {
        JSONArray array = new JSONArray();
        if (Checker.isNotEmpty(list)) {
            array.addAll(list);
        }
        return formatJson(array.toString());
    }
754469
private void _serialize(Object object, StringBuilder sb, Set<Object> done) throws ConverterException {
	// try {
	deep++;
	// NULL
	if (object == null) {
	    sb.append(goIn());
	    sb.append("nullValue()");
	    deep--;
	    return;
	}
	// String
	if (object instanceof String) {
	    sb.append(goIn());
	    sb.append(QUOTE_CHR);
	    sb.append(escape(object.toString()));
	    sb.append(QUOTE_CHR);
	    deep--;
	    return;
	}
	if (object instanceof TimeZone) {
	    sb.append(goIn());
	    sb.append(QUOTE_CHR);
	    sb.append(escape(((TimeZone) object).getID()));
	    sb.append(QUOTE_CHR);
	    deep--;
	    return;
	}
	if (object instanceof Locale) {
	    sb.append(goIn());
	    sb.append(QUOTE_CHR);
	    sb.append(LocaleFactory.toString((Locale) object));
	    sb.append(QUOTE_CHR);
	    deep--;
	    return;
	}
	// Number
	if (object instanceof Number) {
	    sb.append(goIn());
	    sb.append(Caster.toString(((Number) object)));
	    deep--;
	    return;
	}
	// Boolean
	if (object instanceof Boolean) {
	    sb.append(goIn());
	    sb.append(Caster.toString(((Boolean) object).booleanValue()));
	    deep--;
	    return;
	}
	// DateTime
	if (object instanceof DateTime) {
	    _serializeDateTime((DateTime) object, sb);
	    deep--;
	    return;
	}
	// Date
	if (object instanceof Date) {
	    _serializeDate((Date) object, sb);
	    deep--;
	    return;
	}
	// XML
	if (object instanceof Node) {
	    _serializeXML((Node) object, sb);
	    deep--;
	    return;
	}
	if (object instanceof ObjectWrap) {
	    try {
		_serialize(((ObjectWrap) object).getEmbededObject(), sb, done);
	    }
	    catch (PageException e) {
		throw toConverterException(e);
	    }
	    deep--;
	    return;
	}
	// Timespan
	if (object instanceof TimeSpan) {
	    _serializeTimeSpan((TimeSpan) object, sb);
	    deep--;
	    return;
	}
	Object raw = LazyConverter.toRaw(object);
	if (done.contains(raw)) {
	    sb.append(goIn());
	    sb.append("nullValue()");
	    deep--;
	    return;
	}

	done.add(raw);
	try {
	    // Component
	    if (object instanceof Component) {
		_serializeComponent((Component) object, sb, done);
		deep--;
		return;
	    }

	    // Struct
	    if (object instanceof Struct) {
		_serializeStruct((Struct) object, sb, done);
		deep--;
		return;
	    }
	    // Map
	    if (object instanceof Map) {
		_serializeMap((Map) object, sb, done);
		deep--;
		return;
	    }
	    // Array
	    if (object instanceof Array) {
		_serializeArray((Array) object, sb, done);
		deep--;
		return;
	    }
	    // List
	    if (object instanceof List) {
		_serializeList((List) object, sb, done);
		deep--;
		return;
	    }
	    // Query
	    if (object instanceof Query) {
		_serializeQuery((Query) object, sb, done);
		deep--;
		return;
	    }
	    // String Converter
	    if (object instanceof ScriptConvertable) {
		sb.append(((ScriptConvertable) object).serialize());
		deep--;
		return;
	    }
	    if (object instanceof Serializable) {
		_serializeSerializable((Serializable) object, sb);
		deep--;
		return;
	    }
	}
	finally {
	    done.remove(raw);
	}
	throw new ConverterException("can't serialize Object of type [ " + Caster.toClassName(object) + " ]");
	// deep--;
	/*
	 * } catch(StackOverflowError soe){ throw soe; }
	 */
    }
149998
private void toStringList(final StringBuilder sb, final List < ? > list,
            final String title) {
        sb.append(',');
        sb.append(title + ":[");
        boolean first = true;
        for (Object child : list) {
            if (!first) {
                sb.append(",");
            } else {
                first = false;
            }
            sb.append(child.toString());
        }
        sb.append("]");
    }
448117
private String _serializeQuery(Query query, Map<Object, String> done, String id) throws ConverterException {

	/*
	 * <QUERY ID="1"> <COLUMNNAMES> <COLUMN NAME="a"></COLUMN> <COLUMN NAME="b"></COLUMN> </COLUMNNAMES>
	 * 
	 * <ROWS> <ROW> <COLUMN TYPE="STRING">a1</COLUMN> <COLUMN TYPE="STRING">b1</COLUMN> </ROW> <ROW>
	 * <COLUMN TYPE="STRING">a2</COLUMN> <COLUMN TYPE="STRING">b2</COLUMN> </ROW> </ROWS> </QUERY>
	 */
	Collection.Key[] keys = CollectionUtil.keys(query);
	StringBuilder sb = new StringBuilder(goIn() + "<QUERY ID=\"" + id + "\">");

	// columns
	sb.append(goIn() + "<COLUMNNAMES>");
	for (int i = 0; i < keys.length; i++) {
	    sb.append(goIn() + "<COLUMN NAME=\"" + keys[i].getString() + "\"></COLUMN>");
	}
	sb.append(goIn() + "</COLUMNNAMES>");

	String value;
	deep++;
	sb.append(goIn() + "<ROWS>");
	int len = query.getRecordcount();
	for (int row = 1; row <= len; row++) {
	    sb.append(goIn() + "<ROW>");
	    for (int col = 0; col < keys.length; col++) {
		try {
		    value = _serialize(query.getAt(keys[col], row), done);
		}
		catch (PageException e) {
		    value = _serialize(e.getMessage(), done);
		}
		sb.append("<COLUMN TYPE=\"" + type + "\">" + value + "</COLUMN>");
	    }
	    sb.append(goIn() + "</ROW>");

	}
	sb.append(goIn() + "</ROWS>");
	deep--;

	sb.append(goIn() + "</QUERY>");
	type = "QUERY";
	return sb.toString();
    }
9455
public String serializeTransformList(List<Transform> list) {
        ObjectMapper om = getObjectMapper();
        try {
            return om.writeValueAsString(new ListWrappers.TransformList(list));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
250909
private String _serializeMap(Map map, Set<Object> done) throws ConverterException {
	StringBuilder sb = new StringBuilder(goIn() + "<struct>");

	Iterator it = map.keySet().iterator();

	deep++;
	while (it.hasNext()) {
	    Object key = it.next();
	    sb.append(goIn() + "<var name=" + del + XMLUtil.escapeXMLString(key.toString()) + del + ">");
	    sb.append(_serialize(map.get(key), done));
	    sb.append(goIn() + "</var>");
	}
	deep--;

	sb.append(goIn() + "</struct>");
	return sb.toString();
    }
1232920
@Override
	protected void serializeTo(RawDataBuffer out)
    {
        super.serializeTo(out);
        out.writeInt(sessionId.asInt());
        out.writeInt(consumerId.asInt());
        MessageSerializer.serializeTo(message, out);
        out.writeBoolean(donePrefetching);
    }
763629
private String _serializeArray(Array array, Map<Object, String> done, String id) throws ConverterException {
	return _serializeList(array.toList(), done, id);
    }
936006
private static Object saveList(List<String> list) {
        if ((list == null) || list.isEmpty()) {
            return null;
        }

        int size = list.size();

        if (size == 1) {
            return list.get(0);
        }

        return list.toArray(new String[size]);
    }
220549
public String serializeSequenceComparatorList(List<SequenceComparator> list) {
        ObjectMapper om = getObjectMapper();
        try {
            return om.writeValueAsString(new ListWrappers.SequenceComparatorList(list));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
1087122
private String[] mergeAndConvert(List<String> list, String[] array) {
        Set<String> set = new HashSet<String>(Arrays.asList(array));
        set.addAll(list);
        return set.toArray(new String[set.size()]);
    }
456518
private void _serializeMap(Map map, StringBuilder sb, Set<Object> done) throws ConverterException {
	if (map instanceof Serializable) {
	    _serializeSerializable((Serializable) map, sb);
	    return;
	}
	sb.append(goIn());
	sb.append("{");

	Iterator it = map.keySet().iterator();
	boolean doIt = false;
	deep++;
	while (it.hasNext()) {
	    Object key = it.next();
	    if (doIt) sb.append(',');
	    doIt = true;
	    sb.append(QUOTE_CHR);
	    sb.append(escape(key.toString()));
	    sb.append(QUOTE_CHR);
	    sb.append(':');
	    _serialize(map.get(key), sb, done);
	}
	deep--;

	sb.append('}');
    }
945240
private String _serializeStruct(Struct struct, Set<Object> done) throws ConverterException {
	StringBuilder sb = new StringBuilder(goIn() + "<struct>");

	Iterator<Key> it = struct.keyIterator();

	deep++;
	while (it.hasNext()) {
	    Key key = it.next();
	    sb.append(goIn() + "<var name=" + del + XMLUtil.escapeXMLString(key.toString()) + del + ">");
	    sb.append(_serialize(struct.get(key, null), done));
	    sb.append(goIn() + "</var>");
	}
	deep--;

	sb.append(goIn() + "</struct>");
	return sb.toString();
    }
1216635
def _deserialize_list(cls, type_item, list_):
        

        list_deserialized = []

        for item in list_:
            item_deserialized = cls.deserialize(type_item, item)
            list_deserialized.append(item_deserialized)

        return list_deserialized
417233
public static <T> JSONArray listToJSONArray(final List<T> list) {
        final JSONArray ret = new JSONArray();

        if (null == list) {
            return ret;
        }

        for (final T object : list) {
            ret.put(object);
        }

        return ret;
    }