本文整理汇总了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);
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
}
示例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;
}
}
示例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;
}
示例12: deserialize
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public String deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
return jsonElement.toString();
}
示例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();
}
示例14: setResponse
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public void setResponse(JsonElement response) {
this.response = (JsonObject) response;
this.temp = response.toString();
}