Example usage for com.google.gson JsonDeserializationContext deserialize

List of usage examples for com.google.gson JsonDeserializationContext deserialize

Introduction

In this page you can find the example usage for com.google.gson JsonDeserializationContext deserialize.

Prototype

public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;

Source Link

Document

Invokes default deserialization on the specified object.

Usage

From source file:com.baidu.rigel.biplatform.ac.util.deserialize.DimensionDeserialize.java

License:Open Source License

@Override
public Dimension deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Dimension dimension = null;// ww  w.  j  av  a2 s.  co  m
    if (json.isJsonObject()) {
        JsonObject dimensionObject = json.getAsJsonObject();

        if (dimensionObject.get("type") != null) {
            DimensionType dimensionType = DimensionType.valueOf(dimensionObject.get("type").getAsString());
            if (dimensionType.equals(DimensionType.TIME_DIMENSION)) {
                dimension = context.deserialize(json, TimeDimension.class);
            } else {
                dimension = context.deserialize(json, StandardDimension.class);
            }
            if (dimension != null && MapUtils.isNotEmpty(dimension.getLevels())) {
                for (Level level : dimension.getLevels().values()) {
                    level.setDimension(dimension);
                }
            }
        }
    }
    return dimension;
}

From source file:com.baidu.rigel.biplatform.ac.util.deserialize.LevelDeserialize.java

License:Open Source License

@Override
public Level deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonObject()) {
        JsonObject levelJsonObj = json.getAsJsonObject();

        if (levelJsonObj.get("type") != null) {
            LevelType levelType = LevelType.valueOf(levelJsonObj.get("type").getAsString());
            if (levelType.equals(LevelType.CALL_BACK)) {
                return context.deserialize(levelJsonObj, CallbackLevel.class);
            } else if (levelType.name().equals(LevelType.USER_CUSTOM)) {
                return context.deserialize(levelJsonObj, UserCustomLevel.class);
            } else {
                return context.deserialize(levelJsonObj, MiniCubeLevel.class);
            }/*w  w  w .j a v a  2 s  . c o  m*/

        }
    }

    return null;
}

From source file:com.baidu.rigel.biplatform.ac.util.deserialize.MeasureDeserialize.java

License:Open Source License

@Override
public Measure deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonObject()) {
        JsonObject jsObj = json.getAsJsonObject();

        String agg = jsObj.get("aggregator").getAsString();
        if (agg.equals(Aggregator.CALCULATED.name())) {
            String type = jsObj.get("type").getAsString();
            if (type.equals(MeasureType.CALLBACK.name())) {
                return context.deserialize(jsObj, CallbackMeasure.class);
            }/*w  ww .  ja  va  2s.  co  m*/
            return context.deserialize(jsObj, ExtendMinicubeMeasure.class);
        }
        return context.deserialize(jsObj, MiniCubeMeasure.class);
    }
    return null;
}

From source file:com.baidu.rigel.biplatform.ac.util.deserialize.MetaConditionDeserialize.java

License:Open Source License

@Override
public MetaCondition deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonObject()) {
        JsonObject conditionObj = json.getAsJsonObject();

        MetaType metaType = context.deserialize(conditionObj.get("metaType"), MetaType.class);
        if (metaType.equals(MetaType.Dimension)) {
            return context.deserialize(json, DimensionCondition.class);
        } else {//from www  . jav a 2s.co m
            return context.deserialize(json, MeasureCondition.class);
        }
    }
    return null;
}

From source file:com.bccriskadvisory.link.rest.gson.OptionalAdapter.java

License:Apache License

@Override
public Optional<T> deserialize(JsonElement json, Type optionalType, JsonDeserializationContext context)
        throws JsonParseException {
    final T value = context.deserialize(json, ((ParameterizedType) optionalType).getActualTypeArguments()[0]);
    return Optional.ofNullable(value);
}

From source file:com.berniesanders.fieldthebern.parsing.CanvassDataSerializer.java

License:Apache License

@Override
public CanvassData deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    CanvassData typedContent = null;/*from  w w w. j  av  a  2s. co  m*/
    switch (json.getAsJsonObject().get("type").getAsString()) {
    case ApiAddress.TYPE:
        typedContent = context.deserialize(json, ApiAddress.class);
        break;
    case Person.TYPE:
        typedContent = context.deserialize(json, Person.class);
        break;
    case UserData.TYPE:
        typedContent = context.deserialize(json, UserData.class);
        break;
    default:
        throw new JsonParseException("unknown type:" + json.getAsJsonObject().get("type").getAsString());
    }

    return typedContent;
}

From source file:com.berniesanders.fieldthebern.parsing.CollectionDeserializer.java

License:Apache License

@Override
public ApiItem deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    ApiItem typedContent = null;//from   w w w .  j  a v a 2 s  .  c o m
    switch (json.getAsJsonObject().get("type").getAsString()) {
    case "collection":
        typedContent = context.deserialize(json, Collection.class);
        break;
    case "page":
        typedContent = context.deserialize(json, Page.class);
        break;
    default:
        throw new JsonParseException("unknown type:" + json.getAsJsonObject().get("type").getAsString());
    }

    return typedContent;
}

From source file:com.berniesanders.fieldthebern.parsing.PageContentDeserializer.java

License:Apache License

@Override
public Content deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    //Gson gson = new Gson(); //use a temp gson so we don't trigger a stack overflow.
    //Content untypedContent = gson.fromJson(json, Content.class);

    Content typedContent = null;//from   w w w .j a  va  2s  .c o  m
    switch (json.getAsJsonObject().get("type").getAsString()) {
    case "h1":
        typedContent = context.deserialize(json, H1.class);
        break;
    case "h2":
        typedContent = context.deserialize(json, H2.class);
        break;
    case "h3":
        typedContent = context.deserialize(json, H3.class);
        break;
    case "p":
        typedContent = context.deserialize(json, P.class);
        break;
    case "img":
        typedContent = context.deserialize(json, Img.class);
        break;
    case "nav":
        try {
            typedContent = context.deserialize(json, Nav.class);
        } catch (JsonSyntaxException jsonEx) {
            Timber.e(jsonEx, "Error deserializing a JSON object");
            //use an empty nav item, there is an error in the ftb json
            typedContent = new Nav();
        }
        break;
    case "video":
        typedContent = context.deserialize(json, Video.class);
        break;
    case "quote":
        typedContent = context.deserialize(json, Quote.class);
        break;
    case "list":
        typedContent = context.deserialize(json, List.class);
        break;
    case "iframe":
        typedContent = context.deserialize(json, Iframe.class);
        break;
    default:
        throw new JsonParseException("unknown type:" + json.getAsJsonObject().get("type").getAsString());
    }

    return typedContent;
}

From source file:com.birbit.jsonapi.JsonApiDeserializer.java

License:Apache License

private JsonApiLinks parseLinks(JsonDeserializationContext context, JsonObject jsonObject) {
    JsonElement links = jsonObject.get("links");
    if (links == null || !links.isJsonObject()) {
        return JsonApiLinks.EMPTY;
    }// ww  w . j  a v a  2  s  .c om
    return context.deserialize(links, JsonApiLinks.class);
}

From source file:com.birbit.jsonapi.JsonApiResourceDeserializer.java

License:Apache License

private void parseLinks(JsonDeserializationContext context, T t, JsonObject jsonObject)
        throws IllegalAccessException, InvocationTargetException {
    JsonElement links = jsonObject.get("links");
    if (links != null && links.isJsonObject()) {
        JsonObject linksObject = links.getAsJsonObject();
        Setter linksObjectSetter = linkSetters.get("");
        if (linksObjectSetter != null) {
            linksObjectSetter.setOnObject(t, context.deserialize(links, JsonApiLinks.class));
        }//from  ww w . j  a v  a 2s. c o  m
        for (Map.Entry<String, Setter> entry : linkSetters.entrySet()) {
            JsonElement link = linksObject.get(entry.getKey());
            if (link != null && link.isJsonPrimitive()) {
                entry.getValue().setOnObject(t, link.getAsString());
            }
        }
    }
}