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


Java JsonPrimitive.isString方法代码示例

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


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

示例1: primitive

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
/**
 * Converts a JsonPrimitive into a primitive Boolean, Double, or String.
 * 
 * @param p
 *          : JsonPrimitive
 * @return Boolean, Double, or String
 */
public static Object primitive(JsonPrimitive p) {
  Object retVal = null;
  if (p.isBoolean()) {
    retVal = p.getAsBoolean();
  } else if (p.isNumber()) {
    double doubleVal = p.getAsDouble();

    if (doubleVal == Math.rint(doubleVal)) {
      retVal = (int) doubleVal;
    } else {
      retVal = doubleVal;
    }
  } else if (p.isString()) {
    retVal = p.getAsString();
  }
  return retVal;
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:25,代码来源:Utilities.java

示例2: Parameter

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
public Parameter(JsonObject param) {
    try {
        setNameAndType(param.get("name").getAsString(), param.get("type").getAsString());
        if(param.get("value").isJsonObject()){
            setJsonContent(param.getAsJsonObject("value"));
        } else {
            JsonPrimitive value = param.getAsJsonPrimitive("value");
            if(value.isString()) {
                setStringContent(value.getAsString());
            } else if(value.isNumber()) {
                setDoubleContent(value.getAsDouble());
            } else if(value.isBoolean()) {
                setBooleanContent(value.getAsBoolean());
            }
        }
    } catch (Exception e){
        throw new IllegalArgumentException("invalid parameter structure");
    }
}
 
开发者ID:DesktopRemoteManagement,项目名称:DRM-Desktop,代码行数:20,代码来源:Parameter.java

示例3: keyToString

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private String keyToString(JsonElement keyElement) {
    if (keyElement.isJsonPrimitive()) {
        JsonPrimitive primitive = keyElement.getAsJsonPrimitive();
        if (primitive.isNumber()) {
            return String.valueOf(primitive.getAsNumber());
        }
        if (primitive.isBoolean()) {
            return Boolean.toString(primitive.getAsBoolean());
        }
        if (primitive.isString()) {
            return primitive.getAsString();
        }
        throw new AssertionError();
    } else if (keyElement.isJsonNull()) {
        return "null";
    } else {
        throw new AssertionError();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:20,代码来源:MapTypeAdapterFactory.java

示例4: keyToString

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private String keyToString(JsonElement keyElement) {
  if (keyElement.isJsonPrimitive()) {
    JsonPrimitive primitive = keyElement.getAsJsonPrimitive();
    if (primitive.isNumber()) {
      return String.valueOf(primitive.getAsNumber());
    } else if (primitive.isBoolean()) {
      return Boolean.toString(primitive.getAsBoolean());
    } else if (primitive.isString()) {
      return primitive.getAsString();
    } else {
      throw new AssertionError();
    }
  } else if (keyElement.isJsonNull()) {
    return "null";
  } else {
    throw new AssertionError();
  }
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:19,代码来源:MapTypeAdapterFactory.java

示例5: assertEqualsJsonPrimitive

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private void assertEqualsJsonPrimitive(JsonPrimitive expectedPrimitive, JsonPrimitive actualPrimitive, String path) {
	if (expectedPrimitive.isString()) {
		Assert.assertEquals("strings at " + path + " do not match",
			expectedPrimitive.getAsString(), actualPrimitive.getAsString());
	}
	if (expectedPrimitive.isBoolean()) {
		Assert.assertEquals("booleans at " + path + " do not match",
			expectedPrimitive.getAsBoolean(), actualPrimitive.getAsBoolean());
	}
	if (expectedPrimitive.isNumber()) {
		boolean equal = expectedPrimitive.getAsBigDecimal().compareTo(actualPrimitive.getAsBigDecimal()) == 0;
		Assert.assertTrue("numbers at " + path + " do not match expected <" +
				expectedPrimitive.getAsBigDecimal() + "> but was:<" +
				actualPrimitive.getAsBigDecimal() + ">",
			equal);
	}
	Assert.assertEquals("expected primitive (" + expectedPrimitive + ") and actual primitive (" +
		actualPrimitive + ") at " + path + " are not equal; ", expectedPrimitive, actualPrimitive);
}
 
开发者ID:LogicalOverflow,项目名称:java-champion-gg-wrapper,代码行数:20,代码来源:ChampionGGTest.java

示例6: parseValues

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
public static List<KvEntry> parseValues(JsonObject valuesObject) {
  List<KvEntry> result = new ArrayList<>();
  for (Entry<String, JsonElement> valueEntry : valuesObject.entrySet()) {
    JsonElement element = valueEntry.getValue();
    if (element.isJsonPrimitive()) {
      JsonPrimitive value = element.getAsJsonPrimitive();
      if (value.isString()) {
        result.add(new StringDataEntry(valueEntry.getKey(), value.getAsString()));
      } else if (value.isBoolean()) {
        result.add(new BooleanDataEntry(valueEntry.getKey(), value.getAsBoolean()));
      } else if (value.isNumber()) {
        if (value.getAsString().contains(".")) {
          result.add(new DoubleDataEntry(valueEntry.getKey(), value.getAsDouble()));
        } else {
          result.add(new LongDataEntry(valueEntry.getKey(), value.getAsLong()));
        }
      } else {
        throw new JsonSyntaxException("Can't parse value: " + value);
      }
    } else {
      throw new JsonSyntaxException("Can't parse value: " + element);
    }
  }
  return result;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:26,代码来源:JsonConverter.java

示例7: translateScenarioArguments

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private void translateScenarioArguments(List<Object> parameters) {
    // TODO: Lookup and replace the list of parameters
    // with data from the test data file

    if(testData != null) {
        for(int i=0;i<parameters.size();i++) {
            if(parameters.get(i) instanceof String) {
                String raw = (String)parameters.get(i);
                if(raw.startsWith("$(") && raw.endsWith(")")) {
                    raw = raw.substring("$(".length(), raw.length() - ")".length());

                    String[] pathElements = raw.split("\\.");
                    if(pathElements != null && pathElements.length > 0) {
                        JsonElement elemPointer = testData;
                        for(String element : pathElements) {
                            if(elemPointer.isJsonObject() && elemPointer.getAsJsonObject().has(element)) {
                                elemPointer = elemPointer.getAsJsonObject().get(element);
                                continue;
                            }
                            else {
                                elemPointer = null;
                                break;
                            }
                        }
                        if(elemPointer != null && elemPointer.isJsonPrimitive()) {
                            JsonPrimitive primitive = elemPointer.getAsJsonPrimitive();
                            if(primitive.isString() || primitive.isNumber())
                                parameters.set(i, primitive.getAsString());
                            else if(primitive.isBoolean())
                                parameters.set(i, primitive.getAsBoolean());
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:andrewjc,项目名称:kheera-testrunner-android,代码行数:38,代码来源:FeatureFileExecutor.java

示例8: unwarpPrimitive

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public Object unwarpPrimitive(JsonPrimitive primitive) {
    if (primitive.isBoolean()) {
        return primitive.getAsBoolean();
    } else if (primitive.isNumber()) {
        return primitive.getAsNumber();
    } else if (primitive.isString()) {
        return primitive.getAsString();
    } else {
        throw new IllegalArgumentException("Unknown primitive type: " + primitive);
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:13,代码来源:AbstractGsonConverter.java

示例9: deserialize

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public SchoolClazzDto deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonArray root = json.getAsJsonArray();
    SchoolClazzDto dto = new SchoolClazzDto();
    dto.id = optInt(root, 0);

    JsonPrimitive second = root.get(1).getAsJsonPrimitive();
    if(second.isString()){
        dto.title = second.getAsString();
    } else if(second.isNumber()){
        dto.title = String.valueOf(second.getAsNumber());
    }

    return dto;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:16,代码来源:SchoolClazzDtoAdapter.java

示例10: deserialize

import com.google.gson.JsonPrimitive; //导入方法依赖的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

示例11: getTypeFor

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private org.eclipse.leshan.core.model.ResourceModel.Type getTypeFor(JsonPrimitive val) {
    if (val.isBoolean())
        return org.eclipse.leshan.core.model.ResourceModel.Type.BOOLEAN;
    if (val.isString())
        return org.eclipse.leshan.core.model.ResourceModel.Type.STRING;
    if (val.isNumber()) {
        if (val.getAsDouble() == val.getAsLong()) {
            return org.eclipse.leshan.core.model.ResourceModel.Type.INTEGER;
        } else {
            return org.eclipse.leshan.core.model.ResourceModel.Type.FLOAT;
        }
    }
    // use string as default value
    return org.eclipse.leshan.core.model.ResourceModel.Type.STRING;
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:16,代码来源:LwM2mNodeDeserializer.java

示例12: read

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
public Object read(JsonElement in) {
  
  if (in.isJsonArray()) {
    List<Object> list = new ArrayList<Object>();
    JsonArray arr = in.getAsJsonArray();
    for (JsonElement anArr : arr) {
      list.add(read(anArr));
    }
    return list;
  } else if (in.isJsonObject()) {
    Map<String, Object> map = new LinkedTreeMap<String, Object>();
    JsonObject obj = in.getAsJsonObject();
    Set<Map.Entry<String, JsonElement>> entitySet = obj.entrySet();
    for (Map.Entry<String, JsonElement> entry: entitySet) {
      map.put(entry.getKey(), read(entry.getValue()));
    }
    return map;
  } else if (in.isJsonPrimitive()) {
    JsonPrimitive prim = in.getAsJsonPrimitive();
    if (prim.isBoolean()) {
      return prim.getAsBoolean();
    } else if (prim.isString()) {
      return prim.getAsString();
    } else if (prim.isNumber()) {
      Number num = prim.getAsNumber();
      // here you can handle double int/long values
      // and return any type you want
      // this solution will transform 3.0 float to long values
      if (Math.abs(Math.ceil(num.doubleValue())-num.longValue()) < .0000001) {
        return num.intValue();
      } else {
        return num.doubleValue();
      }
    }
  }
  return null;
}
 
开发者ID:Huawei,项目名称:Server_Management_Common_eSightApi,代码行数:38,代码来源:JsonUtil.java

示例13: getValueType

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private static String getValueType(Object value1) {
    if (value1 instanceof JsonPrimitive) {
        JsonPrimitive jp = (JsonPrimitive) value1;
        if (jp.isNumber() && jp.toString().contains(".")) {
            return "Double";
        }
        return jp.isBoolean() ? "Boolean" : jp.isNumber() ? "Integer" : jp.isString() ? "String" : "String";
    } else if (value1 instanceof JsonObject || value1 instanceof JsonArray || value1 instanceof LinkedHashMap) {
        return "Object[data]";
    }
    return "String";
}
 
开发者ID:ajtdnyy,项目名称:PackagePlugin,代码行数:13,代码来源:MainFrame.java

示例14: merge

import com.google.gson.JsonPrimitive; //导入方法依赖的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

示例15: peek

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
public JsonToken peek() throws IOException {
    if (this.stack.isEmpty()) {
        return JsonToken.END_DOCUMENT;
    }
    Iterator<?> o = peekStack();
    if (o instanceof Iterator) {
        boolean isObject = this.stack.get(this.stack.size() - 2) instanceof JsonObject;
        Iterator<?> iterator = o;
        if (!iterator.hasNext()) {
            return isObject ? JsonToken.END_OBJECT : JsonToken.END_ARRAY;
        } else {
            if (isObject) {
                return JsonToken.NAME;
            }
            this.stack.add(iterator.next());
            return peek();
        }
    } else if (o instanceof JsonObject) {
        return JsonToken.BEGIN_OBJECT;
    } else {
        if (o instanceof JsonArray) {
            return JsonToken.BEGIN_ARRAY;
        }
        if (o instanceof JsonPrimitive) {
            JsonPrimitive primitive = (JsonPrimitive) o;
            if (primitive.isString()) {
                return JsonToken.STRING;
            }
            if (primitive.isBoolean()) {
                return JsonToken.BOOLEAN;
            }
            if (primitive.isNumber()) {
                return JsonToken.NUMBER;
            }
            throw new AssertionError();
        } else if (o instanceof JsonNull) {
            return JsonToken.NULL;
        } else {
            if (o == SENTINEL_CLOSED) {
                throw new IllegalStateException("JsonReader is closed");
            }
            throw new AssertionError();
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:46,代码来源:JsonTreeReader.java


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