package ch.viascom.hipchat.api.deserializer;

import ch.viascom.hipchat.api.models.message.MessageFrom;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

import java.lang.reflect.Type;

/**
 * Created by patrickboesch on 21.04.16.
 */
public class MessageFromDeserializer implements JsonDeserializer<MessageFrom> {

    @Override
    public MessageFrom deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
        MessageFrom messageFrom = new MessageFrom();
        if(jsonElement.isJsonObject()){
            messageFrom.setId(jsonElement.getAsJsonObject().get("id").getAsInt());
            messageFrom.setName(jsonElement.getAsJsonObject().get("name").getAsString());
            messageFrom.setMention_name(jsonElement.getAsJsonObject().get("mention_name").getAsString());
            messageFrom.setVersion(jsonElement.getAsJsonObject().get("version").getAsString());
        } else {
            messageFrom.setName(jsonElement.getAsString());
        }
        return messageFrom;
    }

}

@@ -124,154 +124,9 @@
 son.
-JsonDeserializationContext;%0Aimport com.google.gson.JsonDeserializer;%0Aimport com.google.gson.JsonElement;%0Aimport com.google.gson.JsonParseException
+*
 ;%0A%0Ai
@@ -517,16 +517,17 @@
       if
+ 
 (jsonEle
@@ -546,16 +546,17 @@
 bject())
+ 
 %7B%0A      
@@ -576,357 +576,61 @@
 From
-.setId(jsonElement.getAsJsonObject().get(%22id%22).getAsInt());%0A            messageFrom.setName(jsonElement.getAsJsonObject().get(%22name%22).getAsString());%0A            messageFrom.setMention_name(jsonElement.getAsJsonObject().get(%22mention_name%22).getAsString());%0A            messageFrom.setVersion(jsonElement.getAsJsonObject().get(%22version%22).getAsString()
+ = new Gson().fromJson(jsonElement, MessageFrom.class
 );%0A 

Use default Deserializer for object-type