当前位置: 首页>>代码示例>>Java>>正文


Java JsonElement.toString方法代码示例

本文整理汇总了Java中com.google.gson.JsonElement.toString方法的典型用法代码示例。如果您正苦于以下问题:Java JsonElement.toString方法的具体用法?Java JsonElement.toString怎么用?Java JsonElement.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.JsonElement的用法示例。


在下文中一共展示了JsonElement.toString方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadAlgorithmsOfJsonFile

import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
 * Loads the algorithms defined in the JSON file given in the constructor of this class.
 */
private void loadAlgorithmsOfJsonFile() {
   List<CommandResult> listOfCommandResults = new ArrayList<>();
   for (JsonElement algorithm : multipleLearningAlgorithmsAsJsonArray) {
      AddLearningAlgorithmFromJsonCommand addAlgorithmCommand = new AddLearningAlgorithmFromJsonCommand(algorithm.toString());
      if (addAlgorithmCommand.canBeExecuted()) {
         listOfCommandResults.add(addAlgorithmCommand.executeCommand());
      } else {
         listOfCommandResults.add(CommandResult.createFailureCommandResult(new LoadLearningAlgorithmsFailedException(
               String.format(ERROR_ADDING_ALGORITHM_FAILED, addAlgorithmCommand.getFailureReason()))));
      }
   }

   commandResult = CommandResult.createSuccessCommandResult(listOfCommandResults);
   checkIfAllAlgorithmsFailedToLoad(listOfCommandResults);
}
 
开发者ID:Intelligent-Systems-Group,项目名称:jpl-framework,代码行数:19,代码来源:LoadLearningAlgorithmsCommand.java

示例2: makeConfigParam

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private ConfigurationParam makeConfigParam(String key, JsonElement value) {
    if (value.isJsonNull()) {
        throw new NullPointerException("value for key '" + key + "' is null!");
    }
    ConfigurationParam param = new ConfigurationParam();
    param.setKey(key);
    String valueStr;
    if (value.isJsonPrimitive() && value.getAsJsonPrimitive().isString()) {
        // toString would return the string with quotes around it which we don't want
        valueStr = value.getAsString();
    } else {
        valueStr = value.toString();
    }
    param.setValue(valueStr);
    return param;
}
 
开发者ID:TryGhost,项目名称:Ghost-Android,代码行数:17,代码来源:ConfigurationListDeserializer.java

示例3: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public Color deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
    if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isNumber())
    {
        return new ColorImpl(json.getAsInt());
    } else if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString())
    {
        String s = json.getAsJsonPrimitive().getAsString();

        if (s.matches("[0-9a-fA-F]+"))
        {
            int col = (int) Long.parseLong(s, 16);
            return new ColorImpl(s.length() <= 6 ? 0xff000000 | col : col);
        } else
        {
            return new ColorImpl(registry.getColor(s));
        }
    }

    throw new JsonParseException("Invalid element for color: " + json.toString());
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:23,代码来源:ColorDeserializer.java

示例4: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public UnnamedField deserialize(JsonElement json,
                                Type typeOfT,
                                JsonDeserializationContext context) throws JsonParseException {
    if (!json.isJsonPrimitive()) {
        throw new JsonParseException("Is not a primitive: " + json.toString());
    }

    JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive();

    UnnamedField result = null;

    if (jsonPrimitive.isBoolean()) {
        result = FieldFabric.create(jsonPrimitive.getAsBoolean());
    } else if (jsonPrimitive.isString()) {
        result = FieldFabric.create(jsonPrimitive.getAsString());
    } else if (jsonPrimitive.isNumber()) {
        String numberString = jsonPrimitive.getAsString();
        if (numberString.contains(".")) {
            result = FieldFabric.create(jsonPrimitive.getAsDouble());
        } else {
            result = FieldFabric.create(jsonPrimitive.getAsLong());
        }
    }

    if (result == null) {
        throw new JsonParseException("JsonElement is of unsupported type");
    }

    return result;
}
 
开发者ID:NomenSvyat,项目名称:SwitchBoxPlugin,代码行数:32,代码来源:UnnamedFieldDeserializer.java

示例5: parseEstimates

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private UberCostEstimateDTO[] parseEstimates(String json){
        JsonParser parser = new JsonParser();
        JsonObject jsonObj = (JsonObject) parser.parse(json);
        JsonElement jsonElement = jsonObj.get("prices");
        String jsonString = jsonElement.toString();
        UberCostEstimateDTO[] uberCostEstimates = new GsonBuilder().create().fromJson(jsonString, UberCostEstimateDTO[].class);
/*
        int size = uberCostEstimates.length;
        UberListOfCostEstimateDTOs uberList = new UberListOfCostEstimateDTOs();
        uberList.setUberListOfCostEstimates(uberCostEstimates);
        UberCostEstimateDTO cheapestUber = uberList.getCheapest();
*/
        return uberCostEstimates;
    }
 
开发者ID:mezau532,项目名称:smart_commuter,代码行数:15,代码来源:UberSync.java

示例6: MapValue

import com.google.gson.JsonElement; //导入方法依赖的package包/类
protected MapValue(final JsonElement v, final boolean deprecated, final String encryptionProfile)
{
    super(deprecated, encryptionProfile);

    Type mapType = new TypeToken<Map<String, String>>() {}.getType();
    JsonObject obj = v.getAsJsonObject();
    this.json = v.toString();
    this.value = new Gson().fromJson(obj, mapType);
}
 
开发者ID:ConfigHubPub,项目名称:JavaAPI,代码行数:10,代码来源:Properties.java

示例7: ListValue

import com.google.gson.JsonElement; //导入方法依赖的package包/类
protected ListValue(final JsonElement v, final boolean deprecated, final String encryptionProfile)
{
    super(deprecated, encryptionProfile);

    Type listType = new TypeToken<List<String>>() {}.getType();
    JsonArray arr = v.getAsJsonArray();
    this.json = v.toString();
    this.value = new Gson().fromJson(arr, listType);
}
 
开发者ID:ConfigHubPub,项目名称:JavaAPI,代码行数:10,代码来源:Properties.java

示例8: databeanFromJson

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private static <PK extends PrimaryKey<PK>,D extends Databean<PK,D>>
D databeanFromJson(Supplier<D> databeanSupplier, DatabeanFielder<PK,D> fielder, JsonObject json, boolean flatKey){
	if(json == null){
		return null;
	}
	D databean = databeanSupplier.get();
	JsonObject pkJson;
	if(flatKey){
		pkJson = json;
	}else{
		pkJson = json.getAsJsonObject(databean.getKeyFieldName());
	}
	primaryKeyFromJson(databean.getKey(), fielder.getKeyFielder(), pkJson);
	List<Field<?>> fields = fielder.getNonKeyFields(databean);
	for(Field<?> field : fields){
		String jsonFieldName = field.getKey().getColumnName();
		JsonElement jsonValue = json.get(jsonFieldName);
		if(jsonValue == null || jsonValue.isJsonNull()){// careful: only skip nulls, not empty strings
			continue;
		}
		String valueString;
		if(jsonValue.isJsonObject()){
			valueString = jsonValue.toString();
		}else{
			valueString = jsonValue.getAsString();
		}
		Object value = field.parseStringEncodedValueButDoNotSet(valueString);
		field.setUsingReflection(databean, value);
	}
	return databean;
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:32,代码来源:JsonDatabeanTool.java

示例9: merge

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public void merge(JsonElement json, Builder builder) throws InvalidProtocolBufferException {
	if (json instanceof JsonPrimitive) {
        JsonPrimitive primitive = (JsonPrimitive) json;
        if (primitive.isString())
        {
        	Quantity.Builder b = Quantity.newBuilder().setString(primitive.getAsString());
        	builder.mergeFrom(b.build().toByteArray());
        }
        else throw new InvalidProtocolBufferException("Can't decode io.kubernetes.client.proto.resource.Quantity from "+json.toString());
	}
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:13,代码来源:QuantityUtils.java

示例10: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public Type deserialize(JsonElement json, java.lang.reflect.Type classOfT, JsonDeserializationContext context)
        throws JsonParseException {
    switch(json.toString()) {
        case "\"image\"":
            return Type.IMAGE;
        case "\"gifv\"":
            return Type.GIFV;
        case "\"video\"":
            return Type.VIDEO;
        default:
            return Type.UNKNOWN;
    }
}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:15,代码来源:Attachment.java

示例11: SchemaViolationError

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public SchemaViolationError(AbstractResponse object, String field, JsonElement value) {
    super("Invalid value " + value.toString() + " for field " + object.getClass().getSimpleName() + "." + field);
    this.object = object;
    this.field = field;
    this.value = value;
}
 
开发者ID:Shopify,项目名称:graphql_java_gen,代码行数:7,代码来源:SchemaViolationError.java

示例12: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public String deserialize(JsonElement jsonElement, Type type, 
    JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
  return jsonElement.toString();
}
 
开发者ID:Huawei,项目名称:Server_Management_Common_eSightApi,代码行数:6,代码来源:JsonUtil.java

示例13: retrieveDescriptionFromJson

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private String retrieveDescriptionFromJson(JsonObject response) {
    JsonElement element = response.getAsJsonObject("description").getAsJsonArray("captions").get(0);
    String s = element.toString();
    JsonObject obj = new Gson().fromJson(s, JsonObject.class);
    return obj.get("text").getAsString();
}
 
开发者ID:Augugrumi,项目名称:libris,代码行数:7,代码来源:URLAzureImageSearcher.java

示例14: setResponse

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public void setResponse(JsonElement response) {
    this.response = (JsonObject) response;
    this.temp = response.toString();
}
 
开发者ID:dzikoysk,项目名称:UnknownPandaServer,代码行数:5,代码来源:ResponseClientboundPacket.java


注:本文中的com.google.gson.JsonElement.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。