當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonNull類代碼示例

本文整理匯總了Java中com.google.gson.JsonNull的典型用法代碼示例。如果您正苦於以下問題:Java JsonNull類的具體用法?Java JsonNull怎麽用?Java JsonNull使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonNull類屬於com.google.gson包,在下文中一共展示了JsonNull類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: deserialize

import com.google.gson.JsonNull; //導入依賴的package包/類
@Override
public EntityWrapper deserialize(JsonElement jsonElement, Type typef, JsonDeserializationContext context) throws JsonParseException {
    if (jsonElement == null || jsonElement instanceof JsonNull) {
        return null;
    }

    JsonObject root = jsonElement.getAsJsonObject();

    boolean isNull = root.get(KEY_IS_NULL).getAsBoolean();

    Entity entity = null;
    if (!isNull) {
        int dbotype = root.get(KEY_TYPE).getAsInt();
        entity = context.deserialize(root.get(KEY_ENTITY), AttachmentsTypes.classForType(dbotype));
    }

    return new EntityWrapper(entity);
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:19,代碼來源:DboWrapperAdapter.java

示例2: serialize

import com.google.gson.JsonNull; //導入依賴的package包/類
@Override
public JsonElement serialize(EntityWrapper wrapper, Type type, JsonSerializationContext context) {
    if (wrapper == null) {
        return JsonNull.INSTANCE;
    }

    JsonObject root = new JsonObject();

    Entity entity = wrapper.get();
    root.add(KEY_IS_NULL, new JsonPrimitive(entity == null));

    if (entity != null) {
        root.add(KEY_TYPE, new JsonPrimitive(AttachmentsTypes.typeForInstance(entity)));
        root.add(KEY_ENTITY, context.serialize(entity));
    }

    return root;
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:19,代碼來源:DboWrapperAdapter.java

示例3: toJson

import com.google.gson.JsonNull; //導入依賴的package包/類
private static JsonElement toJson(Object value) {
    if(value instanceof ConfigurationSection) {
        return toJson((ConfigurationSection) value);
    } else if(value instanceof Map) {
        return toJson((Map) value);
    } else if(value instanceof List) {
        return toJson((List) value);
    } else if(value instanceof String) {
        return new JsonPrimitive((String) value);
    } else if(value instanceof Character) {
        return new JsonPrimitive((Character) value);
    } else if(value instanceof Number) {
        return new JsonPrimitive((Number) value);
    } else if(value instanceof Boolean) {
        return new JsonPrimitive((Boolean) value);
    } else if(value == null) {
        return JsonNull.INSTANCE;
    } else {
        throw new IllegalArgumentException("Cannot coerce " + value.getClass().getSimpleName() + " to JSON");
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:22,代碼來源:ConfigUtils.java

示例4: parse

import com.google.gson.JsonNull; //導入依賴的package包/類
public static JsonElement parse(JsonReader reader) throws JsonParseException {
    boolean isEmpty = true;
    try {
        reader.peek();
        isEmpty = false;
        return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader);
    } catch (Throwable e) {
        if (isEmpty) {
            return JsonNull.INSTANCE;
        }
        throw new JsonIOException(e);
    } catch (Throwable e2) {
        throw new JsonSyntaxException(e2);
    } catch (Throwable e22) {
        throw new JsonIOException(e22);
    } catch (Throwable e222) {
        throw new JsonSyntaxException(e222);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:20,代碼來源:Streams.java

示例5: parse

import com.google.gson.JsonNull; //導入依賴的package包/類
public static JsonElement parse(JsonReader reader) throws JsonParseException {
    boolean isEmpty = true;
    try {
        reader.peek();
        isEmpty = false;
        return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader);
    } catch (Throwable e) {
        if (isEmpty) {
            return JsonNull.INSTANCE;
        }
        throw new JsonSyntaxException(e);
    } catch (Throwable e2) {
        throw new JsonSyntaxException(e2);
    } catch (Throwable e22) {
        throw new JsonIOException(e22);
    } catch (Throwable e222) {
        throw new JsonSyntaxException(e222);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:Streams.java

示例6: extractElement

import com.google.gson.JsonNull; //導入依賴的package包/類
public static JsonElement extractElement(JsonElement json, String field) {
    if (json == null) {
        return JsonNull.INSTANCE;
    }

    // We reached the field, return the leaf's value as a string
    if (!field.contains(".")) {
        if (json.isJsonObject()) {
            JsonElement element = ((JsonObject) json).get(field);
            return element == null ? JsonNull.INSTANCE : element;
        } else {
            return JsonNull.INSTANCE;
        }
    }

    int i = field.indexOf('.');
    String key = field.substring(i + 1, field.length());
    JsonElement value = ((JsonObject) json).get(field.substring(0, i));
    return extractElement(value, key);
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:21,代碼來源:JsonUtil.java

示例7: testEqualsNonEmptyArray

import com.google.gson.JsonNull; //導入依賴的package包/類
public void testEqualsNonEmptyArray() {
  JsonArray a = new JsonArray();
  JsonArray b = new JsonArray();

  assertEquals(a, a);

  a.add(new JsonObject());
  assertFalse(a.equals(b));
  assertFalse(b.equals(a));

  b.add(new JsonObject());
  assertEquals(oson.serialize(a), oson.serialize(b));

  a.add(new JsonObject());
  assertFalse(a.equals(b));
  assertFalse(b.equals(a));

  b.add(JsonNull.INSTANCE);
  assertNotEquals(oson.serialize(a), oson.serialize(b));
}
 
開發者ID:osonus,項目名稱:oson,代碼行數:21,代碼來源:JsonArrayTest.java

示例8: serialize

import com.google.gson.JsonNull; //導入依賴的package包/類
@Override
public JsonElement serialize(ILoggingEvent event, Type typeOfSrc, JsonSerializationContext context) {
  JsonObject json = new JsonObject();
  json.addProperty("name", event.getLoggerName());
  json.addProperty("host", hostname);
  json.addProperty("timestamp", Long.toString(event.getTimeStamp()));
  json.addProperty("level", event.getLevel().toString());
  json.addProperty("className", classNameConverter.convert(event));
  json.addProperty("method", methodConverter.convert(event));
  json.addProperty("file", fileConverter.convert(event));
  json.addProperty("line", lineConverter.convert(event));
  json.addProperty("thread", event.getThreadName());
  json.addProperty("message", event.getFormattedMessage());
  json.addProperty("runnableName", runnableName);
  if (event.getThrowableProxy() == null) {
    json.add("throwable", JsonNull.INSTANCE);
  } else {
    json.add("throwable", context.serialize(new DefaultLogThrowable(event.getThrowableProxy()), LogThrowable.class));
  }

  return json;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:23,代碼來源:ILoggingEventSerializer.java

示例9: serialize

import com.google.gson.JsonNull; //導入依賴的package包/類
@Override
public JsonElement serialize(final Pair<Long, Long> src, final java.lang.reflect.Type typeOfSrc, final JsonSerializationContext context) {
    final JsonArray array = new JsonArray();
    if (src.first() != null) {
        array.add(s_gson.toJsonTree(src.first()));
    } else {
        array.add(new JsonNull());
    }

    if (src.second() != null) {
        array.add(s_gson.toJsonTree(src.second()));
    } else {
        array.add(new JsonNull());
    }

    return array;
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:18,代碼來源:Request.java

示例10: serialize

import com.google.gson.JsonNull; //導入依賴的package包/類
@Override
public JsonElement serialize(ScienceProgress scienceProgress, Type typeOfSrc, JsonSerializationContext context) {
    Science science = scienceProgress.getScience();

    if (science.size() > 1) {
        throw new UnsupportedOperationException("Cannot serialize science containing more than one element");
    }

    for (ScienceType type : ScienceType.values()) {
        int quantity = science.getQuantity(type);
        if (quantity == 1) {
            return context.serialize(type);
        }
    }

    if (science.getJokers() == 1) {
        return new JsonPrimitive("any");
    }

    return JsonNull.INSTANCE;
}
 
開發者ID:luxons,項目名稱:seven-wonders,代碼行數:22,代碼來源:ScienceProgressSerializer.java

示例11: serializeInventory

import com.google.gson.JsonNull; //導入依賴的package包/類
private static JsonArray serializeInventory(Inventory inv) {
    JsonArray json = new JsonArray();

    inv.slots().forEach(slot -> {
        Optional<ItemStack> item = slot.peek();
        if (item.isPresent()) {
            try {
                json.add(new JsonPrimitive(SerializationHelper.serialize(item.get())));
            } catch (IOException ex) {
                InfernoCore.logWarning("Failed to serialize ItemStack from inventory");
                ex.printStackTrace();
            }
        } else {
            json.add(JsonNull.INSTANCE);
        }
    });

    return json;
}
 
開發者ID:caseif,項目名稱:Inferno,代碼行數:20,代碼來源:PlayerHelper.java

示例12: deserialize

import com.google.gson.JsonNull; //導入依賴的package包/類
@Override
public BeerOnTopList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
	JsonObject object = json.getAsJsonObject();
	BeerOnTopList beerOnTopList = new BeerOnTopList();
	beerOnTopList.beerId = object.get("BeerID").getAsInt();
	beerOnTopList.beerName = Normalizer.get().cleanHtml(object.get("BeerName").getAsString());
	if (object.has("BeerStyleID") && !(object.get("BeerStyleID") instanceof JsonNull))
		beerOnTopList.styleId = object.get("BeerStyleID").getAsInt();

	if (!(object.get("OverallPctl") instanceof JsonNull))
		beerOnTopList.overallPercentile = object.get("OverallPctl").getAsFloat();
	if (!(object.get("StylePctl") instanceof JsonNull))
		beerOnTopList.stylePercentile = object.get("StylePctl").getAsFloat();
	if (!(object.get("AverageRating") instanceof JsonNull))
		beerOnTopList.weightedRating = object.get("AverageRating").getAsFloat();
	beerOnTopList.rateCount = object.get("RateCount").getAsInt();
	if (object.has("HadIt") && !(object.get("HadIt") instanceof JsonNull))
		beerOnTopList.ratedByUser = object.get("HadIt").getAsInt() == 1;
	return beerOnTopList;
}
 
開發者ID:erickok,項目名稱:ratebeer,代碼行數:21,代碼來源:BeerOnTopListDeserializer.java

示例13: deserialize

import com.google.gson.JsonNull; //導入依賴的package包/類
@Override
public PlaceSearchResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
	JsonObject object = json.getAsJsonObject();
	PlaceSearchResult placeSearchResult = new PlaceSearchResult();
	placeSearchResult.placeId = object.get("PlaceID").getAsInt();
	placeSearchResult.placeName = Normalizer.get().cleanHtml(object.get("PlaceName").getAsString());
	placeSearchResult.placeType = object.get("PlaceType").getAsInt();
	placeSearchResult.city = Normalizer.get().cleanHtml(object.get("City").getAsString());
	if (object.has("CountryID") && !(object.get("CountryID") instanceof JsonNull))
		placeSearchResult.countryId = object.get("CountryID").getAsInt();
	if (object.has("StateId") && !(object.get("StateID") instanceof JsonNull))
		placeSearchResult.stateId = object.get("StateID").getAsInt();
	if (object.has("Percentile") && !(object.get("Percentile") instanceof JsonNull))
		placeSearchResult.overallPercentile = object.get("Percentile").getAsFloat();
	if (object.has("AvgRating") && !(object.get("AvgRating") instanceof JsonNull))
		placeSearchResult.averageRating = object.get("AvgRating").getAsFloat();
	if (object.has("RateCount") && !(object.get("RateCount") instanceof JsonNull))
		placeSearchResult.rateCount = object.get("RateCount").getAsInt();
	return placeSearchResult;
}
 
開發者ID:erickok,項目名稱:ratebeer,代碼行數:21,代碼來源:PlaceSearchResultDeserializer.java

示例14: deserialize

import com.google.gson.JsonNull; //導入依賴的package包/類
@Override
public BeerSearchResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
	JsonObject object = json.getAsJsonObject();
	BeerSearchResult beerSearchResult = new BeerSearchResult();
	beerSearchResult.beerId = object.get("BeerID").getAsInt();
	beerSearchResult.beerName = Normalizer.get().cleanHtml(object.get("BeerName").getAsString());
	beerSearchResult.brewerId = object.get("BrewerID").getAsInt();

	if (!(object.get("OverallPctl") instanceof JsonNull))
		beerSearchResult.overallPercentile = object.get("OverallPctl").getAsFloat();
	beerSearchResult.rateCount = object.get("RateCount").getAsInt();
	if (object.has("Unrateable") && !(object.get("Unrateable") instanceof JsonNull))
		beerSearchResult.unrateable = object.get("Unrateable").getAsBoolean();
	if (object.has("IsAlias") && !(object.get("IsAlias") instanceof JsonNull))
		beerSearchResult.alias = object.get("IsAlias").getAsBoolean();
	beerSearchResult.retired = object.get("Retired").getAsBoolean();
	if (object.has("IsRated") && !(object.get("IsRated") instanceof JsonNull))
		beerSearchResult.ratedByUser = object.get("IsRated").getAsInt() == 1;
	return beerSearchResult;
}
 
開發者ID:erickok,項目名稱:ratebeer,代碼行數:21,代碼來源:BeerSearchResultDeserializer.java

示例15: deserialize

import com.google.gson.JsonNull; //導入依賴的package包/類
@Override
public FeedItem deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
	JsonObject object = json.getAsJsonObject();
	FeedItem feedItem = new FeedItem();
	feedItem.activityId = object.get("ActivityID").getAsInt();
	feedItem.userId = object.get("UserID").getAsInt();
	feedItem.userName = Normalizer.get().cleanHtml(object.get("Username").getAsString());
	feedItem.type = object.get("Type").getAsInt();
	if (!(object.get("LinkID") instanceof JsonNull))
		feedItem.linkId = object.get("LinkID").getAsInt();
	feedItem.linkText = object.get("LinkText").getAsString(); // Keep raw HTML
	if (!(object.get("ActivityNumber") instanceof JsonNull))
		feedItem.activityNumber = object.get("ActivityNumber").getAsInt();
	feedItem.timeEntered = Normalizer.get().parseTime(object.get("TimeEntered").getAsString());
	if (!(object.get("NumComments") instanceof JsonNull))
		feedItem.numComments = object.get("NumComments").getAsInt();
	return feedItem;
}
 
開發者ID:erickok,項目名稱:ratebeer,代碼行數:19,代碼來源:FeedItemDeserializer.java


注:本文中的com.google.gson.JsonNull類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。