Example usage for com.google.gson JsonElement toString

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

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Returns a String representation of this element.

Usage

From source file:com.unovo.frame.utils.gson.deserializer.FloatJsonDeserializer.java

License:Open Source License

@Override
public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    try {/*ww  w. jav  a 2s. c o  m*/
        return json.getAsFloat();
    } catch (Exception e) {
        Logger.i("FloatJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : ""));
        return 0F;
    }
}

From source file:com.unovo.frame.utils.gson.deserializer.IntegerJsonDeserializer.java

License:Open Source License

@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    try {/*from  w w w.  java2 s  .c o m*/
        return json.getAsInt();
    } catch (Exception e) {
        Logger.i("IntegerJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : ""));
        return 0;
    }
}

From source file:com.unovo.frame.utils.gson.deserializer.StringJsonDeserializer.java

License:Open Source License

@Override
public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    try {/*from   w  w  w . j  a va 2s .  com*/
        return json.getAsString();
    } catch (Exception e) {
        Logger.i("StringJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : ""));
        return "";
    }
}

From source file:com.ushahidi.android.data.api.GeoJsonApi.java

License:Open Source License

/**
 * Sets the {@link GeoJsonEntity} entity properties from the {@link JsonElement}
 *
 * @param jsonElement The jsonElement to retrieve the raw JSON string from.
 */// w  w w .j  ava  2 s  .c  o  m
private Observable<GeoJsonEntity> setGeoJson(JsonElement jsonElement) {
    GeoJsonEntity geoJsonEntity = new GeoJsonEntity();
    geoJsonEntity.setGeoJson(jsonElement.toString());
    return Observable.just(geoJsonEntity);
}

From source file:com.ushahidi.android.data.repository.datasource.post.PostApiDataSource.java

License:Open Source License

private GeoJsonEntity setGeoJson(JsonElement jsonElement, Long deploymentId) {
    GeoJsonEntity geoJsonEntity = new GeoJsonEntity();
    geoJsonEntity.setGeoJson(jsonElement.toString());
    geoJsonEntity.setDeploymentId(deploymentId);
    return geoJsonEntity;
}

From source file:com.vmware.admiral.closures.drivers.nashorn.EmbeddedNashornJSDriver.java

License:Open Source License

private Object convertValue(ScriptEngine engine, JsonElement var) throws ScriptException {
    return engine.eval("JSON.parse('" + var.toString() + "')", engine.getContext());
}

From source file:com.vmware.admiral.closures.services.adapter.AdmiralAdapterService.java

License:Open Source License

private void buildDockerImage(ContainerDescription containerDesc, String computeStateLink,
        AdmiralAdapterTaskState state) {
    logInfo("Sending docker image build request of execution container...");

    DockerImageHostRequest request = new DockerImageHostRequest();
    request.operationTypeId = ImageOperationType.BUILD.id;
    String completionServiceCallBack = createImageBuildRequestUri(containerDesc.image, computeStateLink);
    request.serviceTaskCallback = ServiceTaskCallback.create(completionServiceCallBack);
    request.resourceReference = UriUtils.buildUri(getHost(), computeStateLink);

    logInfo("Build image on REMOTE DOCKER HOST: %s ", request.resourceReference);

    request.customProperties = new HashMap<>();
    request.customProperties.putIfAbsent(DOCKER_BUILD_IMAGE_TAG_PROP_NAME, containerDesc.image);
    request.customProperties.putIfAbsent(DOCKER_BUILD_IMAGE_DOCKERFILE_PROP_NAME, "Dockerfile");
    request.customProperties.putIfAbsent(DOCKER_BUILD_IMAGE_FORCERM_PROP_NAME, "true");
    request.customProperties.putIfAbsent(DOCKER_BUILD_IMAGE_NOCACHE_PROP_NAME, "true");

    boolean setTaskUri = mustSetTaskUri(state);
    JsonElement buildArgsObj = prepareBuildArgs(containerDesc, setTaskUri);

    request.customProperties.putIfAbsent(DOCKER_BUILD_IMAGE_BUILDARGS_PROP_NAME, buildArgsObj.toString());

    request.setDockerImageData(loadDockerImageData(containerDesc.image,
            DriverConstants.DOCKER_IMAGE_DATA_FOLDER_NAME, getClass()));

    Operation op = Operation.createPatch(getHost(), ManagementUriParts.ADAPTER_DOCKER_IMAGE_HOST)
            .setBody(request).setReferer(getHost().getUri()).setCompletion((o, ex) -> {
                if (ex != null) {
                    logSevere("Unable to build image on docker host: ", ex);
                    failTask("Unable to build image on docker host: " + computeStateLink, ex);
                    return;
                }//from  www .j  a  v  a2s. c  o  m

                logInfo("Docker build image request sent. Image: %s, host: %s", containerDesc.image,
                        computeStateLink);
            });

    prepareRequest(op, true);
    getHost().sendRequest(op);
}

From source file:com.vmware.admiral.closures.services.closuredescription.ClosureDescriptionService.java

License:Open Source License

private void formatDependencies(ClosureDescription body) {
    if (!ClosureUtils.isEmpty(body.dependencies)
            && body.runtime.equalsIgnoreCase(DriverConstants.RUNTIME_NODEJS_4)) {
        JsonParser parser = new JsonParser();
        JsonElement jsElement = parser.parse(body.dependencies);
        body.dependencies = jsElement.toString();
    }/*  w w  w .j av a 2s. com*/
}

From source file:com.vmware.dcp.common.serialization.ObjectMapTypeConverter.java

License:Open Source License

@Override
public Map<String, Object> deserialize(JsonElement json, Type unused, JsonDeserializationContext context)
        throws JsonParseException {

    if (!json.isJsonObject()) {
        throw new JsonParseException("The json element is not valid");
    }//from w  w w. j  a va2s. com

    Map<String, Object> result = new HashMap<String, Object>();
    JsonObject jsonObject = json.getAsJsonObject();
    for (Entry<String, JsonElement> entry : jsonObject.entrySet()) {
        String key = entry.getKey();
        JsonElement element = entry.getValue();
        if (element.isJsonObject()) {
            result.put(key, element.toString());
        } else if (element.isJsonNull()) {
            result.put(key, null);
        } else if (element.isJsonPrimitive()) {
            result.put(key, element.getAsString());
        } else {
            throw new JsonParseException("The json element is not valid for key:" + key + " value:" + element);
        }
    }
    return result;
}

From source file:com.wallellen.wechat.common.util.json.WxErrorAdapter.java

License:Open Source License

public WxError deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    WxError wxError = new WxError();
    JsonObject wxErrorJsonObject = json.getAsJsonObject();

    if (wxErrorJsonObject.get("errcode") != null && !wxErrorJsonObject.get("errcode").isJsonNull()) {
        wxError.setErrorCode(GsonHelper.getAsPrimitiveInt(wxErrorJsonObject.get("errcode")));
    }//w  w w. ja v  a 2  s  .c  o m
    if (wxErrorJsonObject.get("errmsg") != null && !wxErrorJsonObject.get("errmsg").isJsonNull()) {
        wxError.setErrorMsg(GsonHelper.getAsString(wxErrorJsonObject.get("errmsg")));
    }
    wxError.setJson(json.toString());
    return wxError;
}