// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
//     @Override
//     public void write(Integer value, Writer writer, Context context)
//     {
//         writer.writeInteger(value);
//     }
// }
// 
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
//     @Override
//     public void write(Map<K, V> map, Writer writer, Context context)
//     {
//         int size = map.size();
// 
//         writer.writeArrayStart(size);
// 
//         for (Map.Entry<?, ?> entry : map.entrySet()) {
//             Object key = entry.getKey();
// 
//             if (key instanceof Integer) {
//                 writer.writeKey((Integer) key);
//             } else {
//                 writer.writeKey(key.toString());
//             }
// 
//             context.write(entry.getValue(), writer);
//         }
// 
//         writer.writeArrayEnd();
//     }
// }
// 
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
//     /**
//      * The charset.
//      */
//     private Charset charset;
// 
//     /**
//      * Creates a adapter for strings encoded in UTF-8.
//      */
//     public StringAdapter() {
//         this(Charset.forName("UTF-8"));
//     }
// 
//     /**
//      * Creates a adapter for strings encoded with the specified charset.
//      *
//      * @param charset The charset to encode strings.
//      */
//     public StringAdapter(Charset charset) {
//         this.charset = charset;
//     }
// 
//     @Override
//     public void write(String value, Writer writer, Context context)
//     {
//         writer.writeString(value, this.charset);
//     }
// }
// 
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
//     @Override
//     public boolean shouldSkipField(Field field)
//     {
//         return false;
//     }
// }
// 
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
//     @Override
//     public String getClassName(Class type)
//     {
//         String className = type.getCanonicalName();
//         StringBuilder adapted = new StringBuilder();
// 
//         for (String part : className.split("\\.")) {
//             adapted.append("\\");
// 
//             adapted.append(part.substring(0, 1).toUpperCase());
//             adapted.append(part.substring(1));
//         }
// 
//         return adapted.substring(1);
//     }
// 
//     @Override
//     public String getFieldName(Field field)
//     {
//         return field.getName();
//     }
// }


import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
package com.marcospassos.phpserializer;



/**
 * @author Marcos Passos
 * @since 1.0
 */
public class SerializerTest
{
    @Test
    public void serialize() throws Exception
    {
        AdapterRegistry registry = new AdapterRegistry();
        registry.registerAdapter(Integer.class, new IntegerAdapter());

        Serializer serializer = new Serializer(
            new PsrNamingStrategy(),
            new NoExclusionStrategy(),
            registry
        );

        assertEquals("i:1;", serializer.serialize(1));
    }

    @Test
    public void serializeGenericAdapter() throws Exception
    {
        AdapterRegistry registry = new AdapterRegistry();
        registry.registerAdapter(Map.class, new MapAdapter());
        registry.registerAdapter(String.class, new StringAdapter());
        registry.registerAdapter(Integer.class, new IntegerAdapter());

        Map<Integer, String> map = new HashMap<>();

// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
//     @Override
//     public void write(Integer value, Writer writer, Context context)
//     {
//         writer.writeInteger(value);
//     }
// }
// 
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
//     @Override
//     public void write(Map<K, V> map, Writer writer, Context context)
//     {
//         int size = map.size();
// 
//         writer.writeArrayStart(size);
// 
//         for (Map.Entry<?, ?> entry : map.entrySet()) {
//             Object key = entry.getKey();
// 
//             if (key instanceof Integer) {
//                 writer.writeKey((Integer) key);
//             } else {
//                 writer.writeKey(key.toString());
//             }
// 
//             context.write(entry.getValue(), writer);
//         }
// 
//         writer.writeArrayEnd();
//     }
// }
// 
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
//     /**
//      * The charset.
//      */
//     private Charset charset;
// 
//     /**
//      * Creates a adapter for strings encoded in UTF-8.
//      */
//     public StringAdapter() {
//         this(Charset.forName("UTF-8"));
//     }
// 
//     /**
//      * Creates a adapter for strings encoded with the specified charset.
//      *
//      * @param charset The charset to encode strings.
//      */
//     public StringAdapter(Charset charset) {
//         this.charset = charset;
//     }
// 
//     @Override
//     public void write(String value, Writer writer, Context context)
//     {
//         writer.writeString(value, this.charset);
//     }
// }
// 
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
//     @Override
//     public boolean shouldSkipField(Field field)
//     {
//         return false;
//     }
// }
// 
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
//     @Override
//     public String getClassName(Class type)
//     {
//         String className = type.getCanonicalName();
//         StringBuilder adapted = new StringBuilder();
// 
//         for (String part : className.split("\\.")) {
//             adapted.append("\\");
// 
//             adapted.append(part.substring(0, 1).toUpperCase());
//             adapted.append(part.substring(1));
//         }
// 
//         return adapted.substring(1);
//     }
// 
//     @Override
//     public String getFieldName(Field field)
//     {
//         return field.getName();
//     }
// }


// Path: src/test/java/com/marcospassos/phpserializer/SerializerTest.java
import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

package com.marcospassos.phpserializer;



/**
 * @author Marcos Passos
 * @since 1.0
 */
public class SerializerTest
{
    @Test
    public void serialize() throws Exception
    {
        AdapterRegistry registry = new AdapterRegistry();
        registry.registerAdapter(Integer.class, new IntegerAdapter());

        Serializer serializer = new Serializer(
            new PsrNamingStrategy(),
            new NoExclusionStrategy(),
            registry
        );

        assertEquals("i:1;", serializer.serialize(1));
    }

    @Test
    public void serializeGenericAdapter() throws Exception
    {
        AdapterRegistry registry = new AdapterRegistry();
        registry.registerAdapter(Map.class, new MapAdapter());
        registry.registerAdapter(String.class, new StringAdapter());
        registry.registerAdapter(Integer.class, new IntegerAdapter());

        Map<Integer, String> map = new HashMap<>();

        map.put(1, "foo");