Example usage for com.google.gson JsonElement getAsString

List of usage examples for com.google.gson JsonElement getAsString

Introduction

In this page you can find the example usage for com.google.gson JsonElement getAsString.

Prototype

public String getAsString() 

Source Link

Document

convenience method to get this element as a string value.

Usage

From source file:com.ccc.crest.core.cache.crest.schema.option.AcceptType.java

License:Open Source License

@Override
public AcceptType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Iterator<Entry<String, JsonElement>> objectIter = ((JsonObject) json).entrySet().iterator();
    while (objectIter.hasNext()) {
        Entry<String, JsonElement> objectEntry = objectIter.next();
        String key = objectEntry.getKey();
        JsonElement value = objectEntry.getValue();
        if (AcceptDumpKey.equals(key)) {
            CcpType schemaTypeElement = new CcpType(key);
            GsonBuilder gson = new GsonBuilder();
            gson.registerTypeAdapter(CcpType.class, schemaTypeElement);
            ccpType = gson.create().fromJson(value.getAsString(), CcpType.class);
        } else if (AcceptNameKey.equals(key))
            name = value.getAsString();//from www  .  jav  a  2  s  .  c o  m
        else
            LoggerFactory.getLogger(getClass())
                    .warn(key + " has a field not currently being handled: \n" + objectEntry.toString());
    }
    return this;
}

From source file:com.ccc.crest.core.cache.crest.schema.option.CcpType.java

License:Open Source License

@Override
public CcpType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Iterator<Entry<String, JsonElement>> objectIter = ((JsonObject) json).entrySet().iterator();
    while (objectIter.hasNext()) {
        Entry<String, JsonElement> objectEntry = objectIter.next();
        String key = objectEntry.getKey();
        JsonElement value = objectEntry.getValue();
        if (DescriptionKey.equals(key))
            description = checkNull(value);
        else if (OptionalKey.equals(key))
            optional = value.getAsBoolean();
        else if (ExtraKey.equals(key)) {
            JsonElement objectElement = objectEntry.getValue();
            if (objectElement.isJsonArray()) {
                int size = ((JsonArray) objectElement).size();
                for (int i = 0; i < size; i++) {
                    JsonElement childElement = ((JsonArray) objectElement).get(i);
                    extraData.add(childElement.getAsString());
                }/*from   w w  w.  ja va  2s  .  c o m*/
            } else
                extraData.add(checkNull(value));

        } else if (SubContentKey.equals(key)) {
            if (!value.isJsonNull()) {
                Iterator<Entry<String, JsonElement>> varsIter = ((JsonObject) value).entrySet().iterator();
                do {
                    if (!varsIter.hasNext())
                        break;
                    Entry<String, JsonElement> varsEntry = varsIter.next();
                    CcpType subContent = new CcpType(varsEntry.getKey());
                    subContent = subContent.deserialize(varsEntry.getValue(), typeOfT, context);
                    children.add(subContent);
                } while (true);
            }
        } else if (PrettyTypeKey.equals(key))
            typePrettyName = checkNull(value);
        else if (TypeKey.equals(key))
            type = checkNull(value);
        else
            LoggerFactory.getLogger(getClass())
                    .warn(key + " has a field not currently being handled: \n" + objectEntry.toString());
    }
    return this;
}

From source file:com.ccc.crest.core.cache.crest.schema.option.CcpType.java

License:Open Source License

private String checkNull(JsonElement value) {
    if (value.isJsonNull())
        return null;
    if (NullValue.equals(value.getAsString()))
        return null;
    return value.getAsString();
}

From source file:com.ccc.crest.core.cache.crest.schema.option.ContentType.java

License:Open Source License

@Override
public ContentType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Iterator<Entry<String, JsonElement>> objectIter = ((JsonObject) json).entrySet().iterator();
    while (objectIter.hasNext()) {
        Entry<String, JsonElement> objectEntry = objectIter.next();
        String key = objectEntry.getKey();
        JsonElement value = objectEntry.getValue();
        if (NameKey.equals(key))
            name = value.getAsString();
        else if (JsonDumpKey.equals(key)) {
            Gson gson = new Gson();
            gson.fromJson(value.getAsString(), CcpType.class);
        } else/*from ww  w .jav  a  2  s .c  o m*/
            LoggerFactory.getLogger(getClass())
                    .warn(key + " has a field not currently being handled: \n" + objectEntry.toString());
    }
    return this;
}

From source file:com.ccc.crest.core.cache.crest.schema.option.Representation.java

License:Open Source License

@Override
public Representation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Iterator<Entry<String, JsonElement>> objectIter = ((JsonObject) json).entrySet().iterator();
    while (objectIter.hasNext()) {
        Entry<String, JsonElement> objectEntry = objectIter.next();
        String key = objectEntry.getKey();
        JsonElement value = objectEntry.getValue();
        if (AcceptVersionStrKey.equals(key))
            versionStr = value.getAsString();
        else if (AcceptTypeKey.equals(key)) {
            acceptType = new AcceptType();
            acceptType.deserialize(value, typeOfT, context);

        } else if (VerbKey.equals(key))
            verb = value.getAsString();/*from   w w  w  .  j  a va 2  s . c  om*/
        else if (VersionKey.equals(key))
            version = value.getAsLong();
        else if (ThirdPartyKey.equals(key))
            thirdParty = value.getAsBoolean();
        else if (ContentTypeKey.equals(key)) {
            ContentType contentType = new ContentType();
            contentType.deserialize(value, typeOfT, context);
        } else
            LoggerFactory.getLogger(getClass())
                    .warn(key + " has a field not currently being handled: \n" + objectEntry.toString());
    }
    return this;
}

From source file:com.ccc.crest.core.cache.crest.tournament.MatchesWon.java

License:Open Source License

@Override
public MatchesWon deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Iterator<Entry<String, JsonElement>> objectIter = ((JsonObject) json).entrySet().iterator();
    while (objectIter.hasNext()) {
        Entry<String, JsonElement> objectEntry = objectIter.next();
        String key = objectEntry.getKey();
        JsonElement value = objectEntry.getValue();
        if (BlueStringKey.equals(key))
            blueTeamStr = value.getAsString();
        else if (RedKey.equals(key))
            redTeam = value.getAsLong();
        else if (RedStringKey.equals(key))
            redTeamStr = value.getAsString();
        else if (BlueKey.equals(key))
            blueTeam = value.getAsLong();
        else//w  w  w.  j av  a  2 s.  co  m
            LoggerFactory.getLogger(getClass())
                    .warn(key + " has a field not currently being handled: \n" + objectEntry.toString());
    }
    return this;
}

From source file:com.ccc.crest.core.cache.crest.tournament.Series.java

License:Open Source License

@Override
public Series deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Iterator<Entry<String, JsonElement>> objectIter = ((JsonObject) json).entrySet().iterator();
    while (objectIter.hasNext()) {
        Entry<String, JsonElement> objectEntry = objectIter.next();
        String key = objectEntry.getKey();
        JsonElement value = objectEntry.getValue();
        if (SeriesUrlKey.equals(key)) {
            seriesUrl = new ExternalRef();
            seriesUrl.deserialize(value, typeOfT, context);
        } else if (TypeKey.equals(key))
            type = value.getAsString();
        else if (NameKey.equals(key))
            name = value.getAsString();/*ww  w. j a  v  a2s  .com*/
        else if (TeamStatsKey.equals(key)) {
            JsonElement objectElement = objectEntry.getValue();
            if (!objectElement.isJsonArray())
                throw new JsonParseException("Expected " + TeamStatsKey + " array received json element "
                        + objectElement.toString());
            int size = ((JsonArray) objectElement).size();
            for (int i = 0; i < size; i++) {
                JsonElement childElement = ((JsonArray) objectElement).get(i);
                TeamStats child = new TeamStats();
                teamStats.add(child);
                child.deserialize(childElement, typeOfT, context);
            }
        } else
            LoggerFactory.getLogger(getClass())
                    .warn(key + " has a field not currently being handled: \n" + objectEntry.toString());
    }
    return this;
}

From source file:com.ccc.crest.core.cache.crest.tournament.SeriesElement.java

License:Open Source License

@Override
public SeriesElement deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Iterator<Entry<String, JsonElement>> objectIter = ((JsonObject) json).entrySet().iterator();
    while (objectIter.hasNext()) {
        Entry<String, JsonElement> objectEntry = objectIter.next();
        String key = objectEntry.getKey();
        JsonElement value = objectEntry.getValue();
        if (TotalCountStrKey.equals(key))
            totalCountStr = value.getAsString();
        else if (ItemsKey.equals(key)) {
            JsonElement objectElement = objectEntry.getValue();
            if (!objectElement.isJsonArray())
                throw new JsonParseException(
                        "Expected " + ItemsKey + " array received json element " + objectElement.toString());
            int size = ((JsonArray) objectElement).size();
            for (int i = 0; i < size; i++) {
                JsonElement childElement = ((JsonArray) objectElement).get(i);
                TeamInfo child = new TeamInfo();
                teamInfos.add(child);/*  ww  w.j  a  v  a2 s.c  o m*/
                child.deserialize(childElement, typeOfT, context);
            }
        } else if (PageCountKey.equals(key))
            pageCount = value.getAsLong();
        else if (PageCountStrKey.equals(key))
            pageCountStr = value.getAsString();
        else if (TotalCountKey.equals(key))
            totalCount = value.getAsLong();
        else
            LoggerFactory.getLogger(getClass())
                    .warn(key + " has a field not currently being handled: \n" + objectEntry.toString());
    }
    return this;
}

From source file:com.ccc.crest.core.cache.crest.tournament.Team.java

License:Open Source License

@Override
public Team deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Iterator<Entry<String, JsonElement>> objectIter = ((JsonObject) json).entrySet().iterator();
    while (objectIter.hasNext()) {
        Entry<String, JsonElement> objectEntry = objectIter.next();
        String key = objectEntry.getKey();
        JsonElement value = objectEntry.getValue();
        if (TeamsUrlKey.equals(key))
            teamUrl = value.getAsString();
        else if (NameKey.equals(key))
            teamName = value.getAsString();
        else/* w ww . ja va2  s  .  com*/
            LoggerFactory.getLogger(getClass())
                    .warn(key + " has a field not currently being handled: \n" + objectEntry.toString());
    }
    return this;
}

From source file:com.ccc.crest.core.cache.crest.tournament.TeamInfo.java

License:Open Source License

@Override
public TeamInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Iterator<Entry<String, JsonElement>> objectIter = ((JsonObject) json).entrySet().iterator();
    while (objectIter.hasNext()) {
        Entry<String, JsonElement> objectEntry = objectIter.next();
        String key = objectEntry.getKey();
        JsonElement value = objectEntry.getValue();
        if (RedTeamKey.equals(key)) {
            redTeam = new TeamWrapper();
            redTeam.deserialize(value, typeOfT, context);
        } else if (WonKey.equals(key)) {
            matchesWon = new MatchesWon();
            matchesWon.deserialize(value, typeOfT, context);
        } else if (MatchesKey.equals(key)) {
            matches = new ExternalRef();
            matches.deserialize(value, typeOfT, context);
        } else if (SelfKey.equals(key)) {
            self = new ExternalRef();
            self.deserialize(value, typeOfT, context);
        } else if (WinnerKey.equals(key)) {
            winner = new TeamWrapper();
            winner.deserialize(value, typeOfT, context);
        } else if (LoserKey.equals(key)) {
            loser = new TeamWrapper();
            loser.deserialize(value, typeOfT, context);
        } else if (LengthKey.equals(key))
            length = value.getAsLong();//w  ww .j a va  2 s  .co  m
        else if (LengthStrKey.equals(key))
            lengthStr = value.getAsString();
        else if (BlueTeamKey.equals(key)) {
            blueTeam = new TeamWrapper();
            blueTeam.deserialize(value, typeOfT, context);
        } else if (StructureKey.equals(key)) {
            structure = new Structure();
            structure.deserialize(value, typeOfT, context);
        } else
            LoggerFactory.getLogger(getClass())
                    .warn(key + " has a field not currently being handled: \n" + objectEntry.toString());
    }
    return this;
}