本文整理汇总了Java中com.google.gson.JsonElement.isJsonObject方法的典型用法代码示例。如果您正苦于以下问题:Java JsonElement.isJsonObject方法的具体用法?Java JsonElement.isJsonObject怎么用?Java JsonElement.isJsonObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonElement
的用法示例。
在下文中一共展示了JsonElement.isJsonObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromJson
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public void fromJson(final JsonElement json)
{
if (!json.isJsonObject())
throw new IllegalArgumentException("json is not an object");
JsonObject all = json.getAsJsonObject();
String type = all.get("content-type").getAsString();
JsonElement data = all.get("data");
if (type.equals(this.contentType))
{
this.dataFromJson(data);
}
}
示例2: update
import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
* Method to update config.
* @param file file to store the updated config
* @param data date to write to the config
* @return boolean
*/
public boolean update(final File file, final Object data) {
JsonElement old = JsonUtils.convertObjectToJsonTree(GSON, this);
JsonElement updates = JsonUtils.convertObjectToJsonTree(GSON, data);
boolean success = true;
if (!old.isJsonObject() && !updates.isJsonObject()) {
LOGGER.warning(String.format("Could not update the config at %s as it or the updated data is not an object.", file.getName()));
success = false;
} else {
JsonObject oldObj = old.getAsJsonObject();
JsonObject updatesObj = updates.getAsJsonObject();
update(oldObj, updatesObj);
try (FileWriter fw = new FileWriter(file)) {
String jsonStr = JsonUtils.convertObjectToJson(GSON, oldObj);
fw.write(jsonStr);
fw.close();
} catch (IOException e) {
LOGGER.warning(String.format("Could not save the updated config to %s.", file.getName()));
success = false;
}
}
return success;
}
示例3: parseAnimationFrame
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private AnimationFrame parseAnimationFrame(int frame, JsonElement element)
{
if (element.isJsonPrimitive())
{
return new AnimationFrame(JsonUtils.getInt(element, "frames[" + frame + "]"));
}
else if (element.isJsonObject())
{
JsonObject jsonobject = JsonUtils.getJsonObject(element, "frames[" + frame + "]");
int i = JsonUtils.getInt(jsonobject, "time", -1);
if (jsonobject.has("time"))
{
Validate.inclusiveBetween(1L, 2147483647L, (long)i, "Invalid frame time");
}
int j = JsonUtils.getInt(jsonobject, "index");
Validate.inclusiveBetween(0L, 2147483647L, (long)j, "Invalid frame index");
return new AnimationFrame(j, i);
}
else
{
return null;
}
}
示例4: parseAccountDataEvents
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private void parseAccountDataEvents(JsonObject syncData) {
if(syncData.has("account_data") &&
syncData.get("account_data").isJsonObject()) {
JsonObject accountDataObject = syncData.get("account_data").getAsJsonObject();
if(accountDataObject.has("events") &&
accountDataObject.get("events").isJsonArray()) {
JsonArray accountDataEvents = accountDataObject.get("events").getAsJsonArray();
for(JsonElement eventElement : accountDataEvents) {
if(eventElement.isJsonObject()) {
JsonObject event = eventElement.getAsJsonObject();
parseAccountDataEvent(event);
}
}
}
}
}
示例5: encodeCanonicalElement
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private static void encodeCanonicalElement(JsonElement el, JsonWriterUnchecked writer) {
try {
if (el.isJsonObject()) encodeCanonical(el.getAsJsonObject(), writer);
else if (el.isJsonPrimitive()) writer.jsonValue(el.toString());
else if (el.isJsonArray()) encodeCanonicalArray(el.getAsJsonArray(), writer);
else if (el.isJsonNull()) writer.nullValue();
else throw new JsonCanonicalException("Unexpected JSON type, this is a bug, report!");
} catch (IOException e) {
throw new JsonCanonicalException(e);
}
}
示例6: serialize
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public JsonElement serialize(Holder src, Type type, JsonSerializationContext context) {
JsonObject root = new JsonObject();
JsonElement value = context.serialize(src.value());
root.addProperty("id", src.id());
if (value.isJsonObject()) {
value.getAsJsonObject().addProperty(Holder.TYPE_PROPERTY, src.value().getClass().getName());
}
root.add(VALUE_PROPERTY, value);
return root;
}
示例7: deserialize
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public UserListEntry<K> deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
if (p_deserialize_1_.isJsonObject())
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
UserListEntry<K> userlistentry = UserList.this.createEntry(jsonobject);
return userlistentry;
}
else
{
return null;
}
}
示例8: loadAccount
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public Data loadAccount(String address)
{
try (FileReader reader = new FileReader(this.conf))
{
JsonElement jsonObject = this.gson.fromJson(reader, JsonElement.class);
if (jsonObject != null && jsonObject.isJsonObject() && jsonObject.getAsJsonObject().has(address))
{
JsonObject account = jsonObject.getAsJsonObject().getAsJsonObject(address);
String userid = account.has("user") ? account.get("user").getAsString() : "";
if (account.has("name") && account.has("uuid") && account.has("auth"))
{
String name = account.get("name").getAsString();
String uuid = account.get("uuid").getAsString();
String accessToken = account.get("auth").getAsString();
return new Data(userid, name, uuid, accessToken);
}
else
{
return new Data(userid);
}
}
else
{
return new Data("", "", "", "");
}
}
catch (IOException e)
{
String path = this.conf.getAbsolutePath();
this.logger.info("AuthlibLoginHelper: Find error when loading account to " + path, e);
return new Data("", "", "", "");
}
}
示例9: getMap
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public <K, T, M extends Map<K, T>> void getMap(String key, Class<K> keyType, Class<T> type, M map)
{
JsonElement element = this.getElement(this.element, key);
if ((element == null) || ! element.isJsonObject())
{
throw new DeserializationException(type, this, "Can't find valid value for key: " + key);
}
JsonObject jsonObject = element.getAsJsonObject();
for (Entry<String, JsonElement> entry : jsonObject.entrySet())
{
K keyObj;
if (Serialization.isSimpleType(keyType))
{
keyObj = this.context.deserialize(new JsonPrimitive(entry.getKey()), keyType);
}
else if (this.serialization.isStringSerializable(keyType))
{
keyObj = this.serialization.deserializeFromString(keyType, entry.getKey());
}
else
{
throw new DeserializationException(type, this, "Can't deserialize given string to key: (" + type.getName() + ") -> " + entry.getKey());
}
map.put(keyObj, this.context.deserialize(entry.getValue(), type));
}
}
示例10: write
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public void write(JsonWriter out, JsonElement value) throws IOException {
if (value == null || value.isJsonNull()) {
out.nullValue();
} else if (value.isJsonPrimitive()) {
JsonPrimitive primitive = value.getAsJsonPrimitive();
if (primitive.isNumber()) {
out.value(primitive.getAsNumber());
} else if (primitive.isBoolean()) {
out.value(primitive.getAsBoolean());
} else {
out.value(primitive.getAsString());
}
} else if (value.isJsonArray()) {
out.beginArray();
Iterator it = value.getAsJsonArray().iterator();
while (it.hasNext()) {
write(out, (JsonElement) it.next());
}
out.endArray();
} else if (value.isJsonObject()) {
out.beginObject();
for (Entry<String, JsonElement> e : value.getAsJsonObject().entrySet()) {
out.name((String) e.getKey());
write(out, (JsonElement) e.getValue());
}
out.endObject();
} else {
throw new IllegalArgumentException("Couldn't write " + value.getClass());
}
}
示例11: write
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public void write(JsonWriter out, JsonElement value) throws IOException {
if (value == null || value.isJsonNull()) {
out.nullValue();
} else if (value.isJsonPrimitive()) {
JsonPrimitive primitive = value.getAsJsonPrimitive();
if (primitive.isNumber()) {
out.value(primitive.getAsNumber());
} else if (primitive.isBoolean()) {
out.value(primitive.getAsBoolean());
} else {
out.value(primitive.getAsString());
}
} else if (value.isJsonArray()) {
out.beginArray();
i$ = value.getAsJsonArray().iterator();
while (i$.hasNext()) {
write(out, (JsonElement) i$.next());
}
out.endArray();
} else if (value.isJsonObject()) {
out.beginObject();
for (Entry<String, JsonElement> e : value.getAsJsonObject().entrySet()) {
out.name((String) e.getKey());
write(out, (JsonElement) e.getValue());
}
out.endObject();
} else {
throw new IllegalArgumentException("Couldn't write " + value.getClass());
}
}
示例12: 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;
}
示例13: parseEvents
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private void parseEvents(JsonObject timeline) {
if (timeline.has("events") &&
timeline.get("events").isJsonArray()) {
JsonArray events = timeline.get("events").getAsJsonArray();
for (JsonElement eventElement : events) {
if (eventElement.isJsonObject()) {
parseEventData(eventElement.getAsJsonObject());
}
}
}
}
示例14: toString
import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
* Gets a human-readable description of the given JsonElement's type. For example: "a number (4)"
*/
public static String toString(JsonElement p_151222_0_)
{
String s = org.apache.commons.lang3.StringUtils.abbreviateMiddle(String.valueOf((Object)p_151222_0_), "...", 10);
if (p_151222_0_ == null)
{
return "null (missing)";
}
else if (p_151222_0_.isJsonNull())
{
return "null (json)";
}
else if (p_151222_0_.isJsonArray())
{
return "an array (" + s + ")";
}
else if (p_151222_0_.isJsonObject())
{
return "an object (" + s + ")";
}
else
{
if (p_151222_0_.isJsonPrimitive())
{
JsonPrimitive jsonprimitive = p_151222_0_.getAsJsonPrimitive();
if (jsonprimitive.isNumber())
{
return "a number (" + s + ")";
}
if (jsonprimitive.isBoolean())
{
return "a boolean (" + s + ")";
}
}
return s;
}
}
示例15: jsonAsObject
import com.google.gson.JsonElement; //导入方法依赖的package包/类
protected JsonObject jsonAsObject(JsonElement element, String field) throws SchemaViolationError {
if (!element.isJsonObject()) {
throw new SchemaViolationError(this, field, element);
}
return element.getAsJsonObject();
}