// Path: src/main/java/org/turbogwt/net/serialization/client/DeserializationContext.java
// public abstract class DeserializationContext {
// 
//     private final ContainerFactoryManager containerFactoryManager;
// 
//     public DeserializationContext(ContainerFactoryManager containerFactoryManager) {
//         this.containerFactoryManager = containerFactoryManager;
//     }
// 
//     public <C extends Collection> C getContainerInstance(Class<C> type) {
//         final Factory<C> factory = containerFactoryManager.getFactory(type);
//         if (factory == null)
//             throw new UnableToDeserializeException("Could not get container instance because there's no factory " +
//                     "registered in the requestor.");
//         return factory.get();
//     }
// 
//     protected ContainerFactoryManager getContainerFactoryManager() {
//         return containerFactoryManager;
//     }
// }
// 
// Path: src/main/java/org/turbogwt/net/serialization/client/Serdes.java
// public interface Serdes<T> extends Deserializer<T>, Serializer<T> {
// 
//     /**
//      * Method for accessing type of the Object this de/serializer can handle.
//      *
//      * @return The class which this de/serializer can de/serialize
//      */
//     @Override
//     Class<T> handledType();
// }
// 
// Path: src/main/java/org/turbogwt/net/serialization/client/SerializationContext.java
// public abstract class SerializationContext {
// }


import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.core.client.JsonUtils;
import java.util.Collection;
import java.util.List;
import org.turbogwt.core.collections.client.JsArrayList;
import org.turbogwt.core.util.client.Overlays;
import org.turbogwt.net.serialization.client.DeserializationContext;
import org.turbogwt.net.serialization.client.Serdes;
import org.turbogwt.net.serialization.client.SerializationContext;
/*
 * Copyright 2014 Grow Bit
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.turbogwt.net.serialization.client.json;




/**
 * Serializer/Deserializer of Overlay types.
 *
 * @param <T> The overlay type of the data to be serialized.
 *
 * @author Danilo Reinert
 */
public class OverlaySerdes<T extends JavaScriptObject> implements Serdes<T> {

    private static OverlaySerdes<JavaScriptObject> INSTANCE = new OverlaySerdes<>();

    @SuppressWarnings("unchecked")
    public static <O extends JavaScriptObject> OverlaySerdes<O> getInstance() {
        return (OverlaySerdes<O>) INSTANCE;
    }

    @Override
    @SuppressWarnings("unchecked")
    public Class<T> handledType() {
        return (Class<T>) JavaScriptObject.class;
    }

    @Override
    public String[] contentType() {
        return JsonSerdes.CONTENT_TYPE_PATTERNS;
    }

    @Override
    public String[] accept() {
        return JsonSerdes.ACCEPT_PATTERNS;
    }

    @Override
    public T deserialize(String response, DeserializationContext context) {
        return JsonUtils.safeEval(response);
    }

    @Override
    @SuppressWarnings("unchecked")
    public <C extends Collection<T>> C deserializeAsCollection(Class<C> collectionType, String response,
// Path: src/main/java/org/turbogwt/net/serialization/client/DeserializationContext.java
// public abstract class DeserializationContext {
// 
//     private final ContainerFactoryManager containerFactoryManager;
// 
//     public DeserializationContext(ContainerFactoryManager containerFactoryManager) {
//         this.containerFactoryManager = containerFactoryManager;
//     }
// 
//     public <C extends Collection> C getContainerInstance(Class<C> type) {
//         final Factory<C> factory = containerFactoryManager.getFactory(type);
//         if (factory == null)
//             throw new UnableToDeserializeException("Could not get container instance because there's no factory " +
//                     "registered in the requestor.");
//         return factory.get();
//     }
// 
//     protected ContainerFactoryManager getContainerFactoryManager() {
//         return containerFactoryManager;
//     }
// }
// 
// Path: src/main/java/org/turbogwt/net/serialization/client/Serdes.java
// public interface Serdes<T> extends Deserializer<T>, Serializer<T> {
// 
//     /**
//      * Method for accessing type of the Object this de/serializer can handle.
//      *
//      * @return The class which this de/serializer can de/serialize
//      */
//     @Override
//     Class<T> handledType();
// }
// 
// Path: src/main/java/org/turbogwt/net/serialization/client/SerializationContext.java
// public abstract class SerializationContext {
// }


// Path: src/main/java/org/turbogwt/net/serialization/client/json/OverlaySerdes.java
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.core.client.JsonUtils;
import java.util.Collection;
import java.util.List;
import org.turbogwt.core.collections.client.JsArrayList;
import org.turbogwt.core.util.client.Overlays;
import org.turbogwt.net.serialization.client.DeserializationContext;
import org.turbogwt.net.serialization.client.Serdes;
import org.turbogwt.net.serialization.client.SerializationContext;

/*
 * Copyright 2014 Grow Bit
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.turbogwt.net.serialization.client.json;




/**
 * Serializer/Deserializer of Overlay types.
 *
 * @param <T> The overlay type of the data to be serialized.
 *
 * @author Danilo Reinert
 */
public class OverlaySerdes<T extends JavaScriptObject> implements Serdes<T> {

    private static OverlaySerdes<JavaScriptObject> INSTANCE = new OverlaySerdes<>();

    @SuppressWarnings("unchecked")
    public static <O extends JavaScriptObject> OverlaySerdes<O> getInstance() {
        return (OverlaySerdes<O>) INSTANCE;
    }

    @Override
    @SuppressWarnings("unchecked")
    public Class<T> handledType() {
        return (Class<T>) JavaScriptObject.class;
    }

    @Override
    public String[] contentType() {
        return JsonSerdes.CONTENT_TYPE_PATTERNS;
    }

    @Override
    public String[] accept() {
        return JsonSerdes.ACCEPT_PATTERNS;
    }

    @Override
    public T deserialize(String response, DeserializationContext context) {
        return JsonUtils.safeEval(response);
    }

    @Override
    @SuppressWarnings("unchecked")
    public <C extends Collection<T>> C deserializeAsCollection(Class<C> collectionType, String response,
                                                               DeserializationContext context) {