当前位置: 首页>>代码示例>>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;未经允许,请勿转载。