// Path: src/main/java/net/ilexiconn/magister/container/Message.java
// public class Message implements Serializable {
//     @SerializedName("Id")
//     public int id;
// 
//     @SerializedName("MapId")
//     public int mapId;
// 
//     @SerializedName("MapTitel")
//     public String mapTitle;
// 
//     @SerializedName("Links")
//     public Link[] links;
// 
//     @SerializedName("Onderwerp")
//     public String topic;
// 
//     /* TODO: Afzender */
// 
//     @SerializedName("IngekortBericht")
//     public String shortMessage;
// 
//     /* TODO: Ontvangers */
// 
//     @SerializedName("VerstuurdOp")
//     public String sentOn;
// 
//     @SerializedName("IsGelezen")
//     public boolean isRead;
// 
//     @SerializedName("Status")
//     public int status;
// 
//     @SerializedName("HeeftPrioriteit")
//     public boolean hasPriority;
// 
//     @SerializedName("HeeftBijlagen")
//     public boolean hasAttachments;
// 
//     public MessageType type;
// }
// 
// Path: src/main/java/net/ilexiconn/magister/container/type/MessageType.java
// public enum MessageType implements Serializable {
//     MESSAGE("Bericht", 1),
//     ANNOUNCEMENT("Mededeling", 2);
// 
//     private String name;
//     private int id;
// 
//     MessageType(String name, int id) {
//         this.name = name;
//         this.id = id;
//     }
// 
//     public static MessageType getTypeById(int i) {
//         for (MessageType type : values()) {
//             if (type.getID() == i) {
//                 return type;
//             }
//         }
//         return null;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public int getID() {
//         return id;
//     }
// }
// 
// Path: src/main/java/net/ilexiconn/magister/util/GsonUtil.java
// public class GsonUtil {
//     private static Gson gson = new Gson();
//     private static JsonParser parser = new JsonParser();
// 
//     public static Gson getGson() {
//         return gson;
//     }
// 
//     public static JsonElement getFromJson(String json, String key) {
//         return parser.parse(json).getAsJsonObject().get(key);
//     }
// 
//     public static Gson getGsonWithAdapter(Class<?> type, TypeAdapter<?> adapter) {
//         Map<Class<?>, TypeAdapter<?>> map = new HashMap<Class<?>, TypeAdapter<?>>();
//         map.put(type, adapter);
//         return getGsonWithAdapters(map);
//     }
// 
//     public static Gson getGsonWithAdapters(Map<Class<?>, TypeAdapter<?>> map) {
//         GsonBuilder builder = new GsonBuilder();
//         for (Map.Entry<Class<?>, TypeAdapter<?>> entry : map.entrySet()) {
//             builder.registerTypeAdapter(entry.getKey(), entry.getValue());
//         }
//         return builder.create();
//     }
// }


import net.ilexiconn.magister.util.GsonUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.*;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import net.ilexiconn.magister.container.Message;
import net.ilexiconn.magister.container.type.MessageType;
/*
 * Copyright (c) 2015 iLexiconn
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

package net.ilexiconn.magister.adapter;



public class MessageAdapter extends TypeAdapter<Message[]> {
    public Gson gson = GsonUtil.getGson();

    @Override
    public void write(JsonWriter out, Message[] value) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public Message[] read(JsonReader in) throws IOException {
        JsonObject object = gson.getAdapter(JsonElement.class).read(in).getAsJsonObject();
        JsonArray array = object.get("Items").getAsJsonArray();
        List<Message> messageList = new ArrayList<Message>();
        for (JsonElement element : array) {
            Message message = gson.fromJson(element, Message.class);
// Path: src/main/java/net/ilexiconn/magister/container/Message.java
// public class Message implements Serializable {
//     @SerializedName("Id")
//     public int id;
// 
//     @SerializedName("MapId")
//     public int mapId;
// 
//     @SerializedName("MapTitel")
//     public String mapTitle;
// 
//     @SerializedName("Links")
//     public Link[] links;
// 
//     @SerializedName("Onderwerp")
//     public String topic;
// 
//     /* TODO: Afzender */
// 
//     @SerializedName("IngekortBericht")
//     public String shortMessage;
// 
//     /* TODO: Ontvangers */
// 
//     @SerializedName("VerstuurdOp")
//     public String sentOn;
// 
//     @SerializedName("IsGelezen")
//     public boolean isRead;
// 
//     @SerializedName("Status")
//     public int status;
// 
//     @SerializedName("HeeftPrioriteit")
//     public boolean hasPriority;
// 
//     @SerializedName("HeeftBijlagen")
//     public boolean hasAttachments;
// 
//     public MessageType type;
// }
// 
// Path: src/main/java/net/ilexiconn/magister/container/type/MessageType.java
// public enum MessageType implements Serializable {
//     MESSAGE("Bericht", 1),
//     ANNOUNCEMENT("Mededeling", 2);
// 
//     private String name;
//     private int id;
// 
//     MessageType(String name, int id) {
//         this.name = name;
//         this.id = id;
//     }
// 
//     public static MessageType getTypeById(int i) {
//         for (MessageType type : values()) {
//             if (type.getID() == i) {
//                 return type;
//             }
//         }
//         return null;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public int getID() {
//         return id;
//     }
// }
// 
// Path: src/main/java/net/ilexiconn/magister/util/GsonUtil.java
// public class GsonUtil {
//     private static Gson gson = new Gson();
//     private static JsonParser parser = new JsonParser();
// 
//     public static Gson getGson() {
//         return gson;
//     }
// 
//     public static JsonElement getFromJson(String json, String key) {
//         return parser.parse(json).getAsJsonObject().get(key);
//     }
// 
//     public static Gson getGsonWithAdapter(Class<?> type, TypeAdapter<?> adapter) {
//         Map<Class<?>, TypeAdapter<?>> map = new HashMap<Class<?>, TypeAdapter<?>>();
//         map.put(type, adapter);
//         return getGsonWithAdapters(map);
//     }
// 
//     public static Gson getGsonWithAdapters(Map<Class<?>, TypeAdapter<?>> map) {
//         GsonBuilder builder = new GsonBuilder();
//         for (Map.Entry<Class<?>, TypeAdapter<?>> entry : map.entrySet()) {
//             builder.registerTypeAdapter(entry.getKey(), entry.getValue());
//         }
//         return builder.create();
//     }
// }


// Path: src/main/java/net/ilexiconn/magister/adapter/MessageAdapter.java
import net.ilexiconn.magister.util.GsonUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.*;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import net.ilexiconn.magister.container.Message;
import net.ilexiconn.magister.container.type.MessageType;

/*
 * Copyright (c) 2015 iLexiconn
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

package net.ilexiconn.magister.adapter;



public class MessageAdapter extends TypeAdapter<Message[]> {
    public Gson gson = GsonUtil.getGson();

    @Override
    public void write(JsonWriter out, Message[] value) throws IOException {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override
    public Message[] read(JsonReader in) throws IOException {
        JsonObject object = gson.getAdapter(JsonElement.class).read(in).getAsJsonObject();
        JsonArray array = object.get("Items").getAsJsonArray();
        List<Message> messageList = new ArrayList<Message>();
        for (JsonElement element : array) {
            Message message = gson.fromJson(element, Message.class);
            message.type = MessageType.getTypeById(element.getAsJsonObject().get("Soort").getAsInt());