/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.ocelotds.marshallers;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.enterprise.inject.Instance;
import org.ocelotds.Constants;
import org.ocelotds.IServicesProvider;
import org.ocelotds.marshalling.JsonMarshaller;
import org.ocelotds.marshalling.exceptions.JsonMarshallingException;

/**
 *
 * @author hhfrancois
 */
public class IServiceProviderMarshaller implements JsonMarshaller<Instance<IServicesProvider>> {

	/**
	 *
	 * @param jsonServicesProviders
	 * @return
	 * @throws JsonMarshallingException
	 */
	@Override
	public String toJson(Instance<IServicesProvider> jsonServicesProviders) throws JsonMarshallingException {
		if (jsonServicesProviders != null) {
			try (OutputStream out = new ByteArrayOutputStream()) {
				out.write("[".getBytes(Constants.UTF_8));
				boolean first = true;
				for (IServicesProvider servicesProvider : jsonServicesProviders) {
					if (!first) {
						out.write(",\n".getBytes(Constants.UTF_8));
					}
					first = false;
					servicesProvider.streamJavascriptServices(out);
				}
				out.write("]".getBytes(Constants.UTF_8));
				return out.toString();
			} catch (IOException e) {
			}
		}
		return "[]";
	}
}

@@ -1263,29 +1263,11 @@
 %09%09%09%09
-first = false;%0D%0A%09%09%09%09%09
+if(
 serv
@@ -1308,17 +1308,49 @@
 ces(out)
-;
+) %7B%0D%0A%09%09%09%09%09%09first = false;%0D%0A%09%09%09%09%09%7D
 %0D%0A%09%09%09%09%7D%0D

fix bug provider return empty