Created
January 29, 2018 11:04
-
-
Save nickname55/fb217ac7bd1dee321c7699235e978109 to your computer and use it in GitHub Desktop.
example json deserializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.pampushko.confluence.rest; | |
import com.google.gson.*; | |
import lombok.extern.slf4j.Slf4j; | |
import java.lang.reflect.Type; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* | |
*/ | |
@Slf4j | |
public class MyDeserializer<T> implements JsonDeserializer<T> | |
{ | |
@Override | |
public T deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException | |
{ | |
JsonObject jo = jsonElement.getAsJsonObject(); | |
if (jo.isJsonObject()) | |
{ | |
return new Gson().fromJson(jsonElement, type); | |
} | |
else | |
{ | |
T p = jsonDeserializationContext.deserialize(jo, type); | |
List<T> pList = new ArrayList<T>(1); | |
pList.add(p); | |
// ProjectContainer pc = new ProjectContainer(); | |
// pc.setProjects(pList); | |
// return pc; | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment