當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。