com.google.gson.JsonNull Java Examples
The following examples show how to use
com.google.gson.JsonNull.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: twill Author: apache File: ILoggingEventSerializer.java License: Apache License 2.0 | 6 votes |
@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; }
Example #2
Source Project: arcusplatform Author: arcus-smart-home File: FormattedMessageWriter.java License: Apache License 2.0 | 6 votes |
private JsonElement getValue(JsonObject payload, String[] parts, int index) { String name = parts[index]; JsonElement e = payload.get(name); if(e == null) { e = JsonNull.INSTANCE; } index++; if(index == parts.length) { return e; } if(e.isJsonObject()) { return getValue(e.getAsJsonObject(), parts, index); } else if(e.isJsonArray()) { return getValue(e.getAsJsonArray(), parts, index); } else { return e; } }
Example #3
Source Project: LiquidBounce Author: CCBlueX File: ModulesConfig.java License: GNU General Public License v3.0 | 6 votes |
/** * Load config from file * * @throws IOException */ @Override protected void loadConfig() throws IOException { final JsonElement jsonElement = new JsonParser().parse(new BufferedReader(new FileReader(getFile()))); if(jsonElement instanceof JsonNull) return; final Iterator<Map.Entry<String, JsonElement>> entryIterator = jsonElement.getAsJsonObject().entrySet().iterator(); while(entryIterator.hasNext()) { final Map.Entry<String, JsonElement> entry = entryIterator.next(); final Module module = LiquidBounce.moduleManager.getModule(entry.getKey()); if(module != null) { final JsonObject jsonModule = (JsonObject) entry.getValue(); module.setState(jsonModule.get("State").getAsBoolean()); module.setKeyBind(jsonModule.get("KeyBind").getAsInt()); if(jsonModule.has("Array")) module.setArray(jsonModule.get("Array").getAsBoolean()); } } }
Example #4
Source Project: ratebeer Author: erickok File: PlaceSearchResultDeserializer.java License: GNU General Public License v3.0 | 6 votes |
@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; }
Example #5
Source Project: ratebeer Author: erickok File: BeerSearchResultDeserializer.java License: GNU General Public License v3.0 | 6 votes |
@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; }
Example #6
Source Project: o2oa Author: o2oa File: DateSerializer.java License: GNU Affero General Public License v3.0 | 6 votes |
public JsonElement serialize(Date date, Type type, JsonSerializationContext context) { if (null == date) { return JsonNull.INSTANCE; } else { Calendar cal = Calendar.getInstance(); cal.setTime(date); if ((cal.get(Calendar.YEAR) == 1970) && (cal.get(Calendar.MONTH) == 0) && (cal.get(Calendar.DATE) == 1)) { /** 如果只有时间内容,日期格式为默认值,那么仅输出时间 */ return new JsonPrimitive(DateTools.format(date, DateTools.format_HHmmss)); } else if ((cal.get(Calendar.HOUR_OF_DAY) == 0) && (cal.get(Calendar.MINUTE) == 0) && (cal.get(Calendar.SECOND) == 0)) { /** 如果仅有日期内容,时间内容全部为0,那么仅仅输出日期 */ return new JsonPrimitive(DateTools.format(date, DateTools.format_yyyyMMdd)); } else { return new JsonPrimitive(DateTools.format(date)); } } }
Example #7
Source Project: ProjectAres Author: OvercastNetwork File: ConfigUtils.java License: GNU Affero General Public License v3.0 | 6 votes |
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"); } }
Example #8
Source Project: mapbox-plugins-android Author: mapbox File: Circle.java License: BSD 2-Clause "Simplified" License | 6 votes |
@Override void setUsedDataDrivenProperties() { if (!(jsonObject.get(CircleOptions.PROPERTY_CIRCLE_RADIUS) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(CircleOptions.PROPERTY_CIRCLE_RADIUS); } if (!(jsonObject.get(CircleOptions.PROPERTY_CIRCLE_COLOR) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(CircleOptions.PROPERTY_CIRCLE_COLOR); } if (!(jsonObject.get(CircleOptions.PROPERTY_CIRCLE_BLUR) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(CircleOptions.PROPERTY_CIRCLE_BLUR); } if (!(jsonObject.get(CircleOptions.PROPERTY_CIRCLE_OPACITY) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(CircleOptions.PROPERTY_CIRCLE_OPACITY); } if (!(jsonObject.get(CircleOptions.PROPERTY_CIRCLE_STROKE_WIDTH) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(CircleOptions.PROPERTY_CIRCLE_STROKE_WIDTH); } if (!(jsonObject.get(CircleOptions.PROPERTY_CIRCLE_STROKE_COLOR) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(CircleOptions.PROPERTY_CIRCLE_STROKE_COLOR); } if (!(jsonObject.get(CircleOptions.PROPERTY_CIRCLE_STROKE_OPACITY) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(CircleOptions.PROPERTY_CIRCLE_STROKE_OPACITY); } }
Example #9
Source Project: letv Author: JackChan1999 File: Streams.java License: Apache License 2.0 | 6 votes |
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); } }
Example #10
Source Project: ratebeer Author: erickok File: BeerOnTopListDeserializer.java License: GNU General Public License v3.0 | 6 votes |
@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; }
Example #11
Source Project: ratebeer Author: erickok File: BreweryDetailsDeserializer.java License: GNU General Public License v3.0 | 5 votes |
@Override public BreweryDetails deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject object = json.getAsJsonObject(); BreweryDetails breweryDetails = new BreweryDetails(); breweryDetails.brewerId = object.get("BrewerID").getAsInt(); breweryDetails.brewerName = Normalizer.get().cleanHtml(object.get("BrewerName").getAsString()); breweryDetails.brewerType = object.get("BrewerTypeID").getAsInt(); breweryDetails.retired = object.get("retired").getAsBoolean(); breweryDetails.address = Normalizer.get().cleanHtml(object.get("BrewerAddress").getAsString()); breweryDetails.city = Normalizer.get().cleanHtml(object.get("BrewerCity").getAsString()); if (object.has("BrewerZipCode") && !(object.get("BrewerZipCode") instanceof JsonNull)) breweryDetails.postalCode = Normalizer.get().cleanHtml(object.get("BrewerZipCode").getAsString()); if (object.has("BrewerCountryID") && !(object.get("BrewerCountryID") instanceof JsonNull)) breweryDetails.countryId = object.get("BrewerCountryID").getAsInt(); if (object.has("BrewerStateID") && !(object.get("BrewerStateID") instanceof JsonNull)) breweryDetails.stateId = object.get("BrewerStateID").getAsInt(); if (object.has("BrewerPhone") && !(object.get("BrewerPhone") instanceof JsonNull)) breweryDetails.phoneNumber = Normalizer.get().cleanHtml(object.get("BrewerPhone").getAsString()); if (object.has("BrewerEmail") && !(object.get("BrewerEmail") instanceof JsonNull)) breweryDetails.email = Normalizer.get().cleanHtml(object.get("BrewerEmail").getAsString()); if (object.has("BrewerWebSite") && !(object.get("BrewerWebSite") instanceof JsonNull)) breweryDetails.websiteUrl = Normalizer.get().cleanHtml(object.get("BrewerWebSite").getAsString()); if (object.has("Facebook") && !(object.get("Facebook") instanceof JsonNull)) breweryDetails.facebook = Normalizer.get().cleanHtml(object.get("Facebook").getAsString()); if (object.has("Twitter") && !(object.get("Twitter") instanceof JsonNull)) breweryDetails.twitter = Normalizer.get().cleanHtml(object.get("Twitter").getAsString()); return breweryDetails; }
Example #12
Source Project: cosmic Author: MissionCriticalCloud File: Request.java License: Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(final List<PortConfig> src, final Type typeOfSrc, final JsonSerializationContext context) { if (src.size() == 0) { return new JsonNull(); } final JsonArray array = new JsonArray(); for (final PortConfig pc : src) { array.add(s_gson.toJsonTree(pc)); } return array; }
Example #13
Source Project: Migrate2Postgres Author: isapir File: Util.java License: GNU General Public License v3.0 | 5 votes |
/** * Returns a JSON sub-element from the given JsonElement and the given path * * @param json - a Gson JsonElement * @param path - a JSON path, e.g. a.b.c[2].d * @return */ public static JsonElement getJsonElement(JsonElement json, String path){ String[] parts = path.split("\\.|\\[|\\]"); JsonElement result = json; for (String key : parts) { key = key.trim(); if (key.isEmpty()) continue; if (result == null){ result = JsonNull.INSTANCE; break; } if (result.isJsonObject()){ result = ((JsonObject)result).get(key); } else if (result.isJsonArray()){ int ix = Integer.valueOf(key) - 1; result = ((JsonArray)result).get(ix); } else break; } return result; }
Example #14
Source Project: DataFixerUpper Author: Mojang File: JsonOps.java License: MIT License | 5 votes |
@Override public <U> U convertTo(final DynamicOps<U> outOps, final JsonElement input) { if (input instanceof JsonObject) { return convertMap(outOps, input); } if (input instanceof JsonArray) { return convertList(outOps, input); } if (input instanceof JsonNull) { return outOps.empty(); } final JsonPrimitive primitive = input.getAsJsonPrimitive(); if (primitive.isString()) { return outOps.createString(primitive.getAsString()); } if (primitive.isBoolean()) { return outOps.createBoolean(primitive.getAsBoolean()); } final BigDecimal value = primitive.getAsBigDecimal(); try { final long l = value.longValueExact(); if ((byte) l == l) { return outOps.createByte((byte) l); } if ((short) l == l) { return outOps.createShort((short) l); } if ((int) l == l) { return outOps.createInt((int) l); } return outOps.createLong(l); } catch (final ArithmeticException e) { final double d = value.doubleValue(); if ((float) d == d) { return outOps.createFloat((float) d); } return outOps.createDouble(d); } }
Example #15
Source Project: DataFixerUpper Author: Mojang File: JsonOps.java License: MIT License | 5 votes |
@Override public DataResult<Stream<Pair<JsonElement, JsonElement>>> getMapValues(final JsonElement input) { if (!(input instanceof JsonObject)) { return DataResult.error("Not a JSON object: " + input); } return DataResult.success(input.getAsJsonObject().entrySet().stream().map(entry -> Pair.of(new JsonPrimitive(entry.getKey()), entry.getValue() instanceof JsonNull ? null : entry.getValue()))); }
Example #16
Source Project: DataFixerUpper Author: Mojang File: JsonOps.java License: MIT License | 5 votes |
@Override public DataResult<Consumer<BiConsumer<JsonElement, JsonElement>>> getMapEntries(final JsonElement input) { if (!(input instanceof JsonObject)) { return DataResult.error("Not a JSON object: " + input); } return DataResult.success(c -> { for (final Map.Entry<String, JsonElement> entry : input.getAsJsonObject().entrySet()) { c.accept(createString(entry.getKey()), entry.getValue() instanceof JsonNull ? null : entry.getValue()); } }); }
Example #17
Source Project: DataFixerUpper Author: Mojang File: JsonOps.java License: MIT License | 5 votes |
@Override public DataResult<Stream<JsonElement>> getStream(final JsonElement input) { if (input instanceof JsonArray) { return DataResult.success(StreamSupport.stream(input.getAsJsonArray().spliterator(), false).map(e -> e instanceof JsonNull ? null : e)); } return DataResult.error("Not a json array: " + input); }
Example #18
Source Project: hmftools Author: hartwigmedical File: MetaDataResolver.java License: GNU General Public License v3.0 | 5 votes |
@Nullable private static String sampleIdP5(@NotNull JsonObject metadata, @NotNull String objectName) { JsonObject object = metadata.getAsJsonObject(objectName); if (object == null) { return null; } JsonElement sampleId = object.get("sampleName"); return sampleId != null && !(sampleId instanceof JsonNull) ? sampleId.getAsString() : null; }
Example #19
Source Project: graphouse Author: ClickHouse File: MetricDataRowCallbackHandlerTest.java License: Apache License 2.0 | 5 votes |
private JsonArray createPoints(double... values) { JsonArray points = new JsonArray(); for (double value : values) { if (Double.isFinite(value)) { points.add(new JsonPrimitive(value)); } else { points.add(JsonNull.INSTANCE); } } return points; }
Example #20
Source Project: helper Author: lucko File: GsonTypeSerializer.java License: MIT License | 5 votes |
@Override public JsonElement deserialize(TypeToken<?> type, ConfigurationNode from) throws ObjectMappingException { if (from.getValue() == null) { return JsonNull.INSTANCE; } if (from.hasListChildren()) { List<? extends ConfigurationNode> childrenList = from.getChildrenList(); JsonArray array = new JsonArray(); for (ConfigurationNode node : childrenList) { array.add(node.getValue(TYPE)); } return array; } if (from.hasMapChildren()) { Map<Object, ? extends ConfigurationNode> childrenMap = from.getChildrenMap(); JsonObject object = new JsonObject(); for (Map.Entry<Object, ? extends ConfigurationNode> ent : childrenMap.entrySet()) { object.add(ent.getKey().toString(), ent.getValue().getValue(TYPE)); } return object; } Object val = from.getValue(); try { return GsonConverters.IMMUTABLE.wrap(val); } catch (IllegalArgumentException e) { throw new ObjectMappingException(e); } }
Example #21
Source Project: neoscada Author: eclipse File: VariantJsonSerializer.java License: Eclipse Public License 1.0 | 5 votes |
@Override public JsonElement serialize ( final Variant src, final Type typeOfSrc, final JsonSerializationContext context ) { if ( src == null ) { return JsonNull.INSTANCE; } final JsonObject result = new JsonObject (); result.addProperty ( VariantJson.FIELD_TYPE, src.getType ().toString () ); switch ( src.getType () ) { case BOOLEAN: result.addProperty ( VariantJson.FIELD_VALUE, src.asBoolean ( null ) ); break; case DOUBLE: //$FALL-THROUGH$ case INT32: //$FALL-THROUGH$ case INT64: result.addProperty ( VariantJson.FIELD_VALUE, (Number)src.getValue () ); break; case STRING: result.addProperty ( VariantJson.FIELD_VALUE, src.asString ( null ) ); break; case NULL: result.add ( VariantJson.FIELD_VALUE, JsonNull.INSTANCE ); break; default: throw new RuntimeException ( String.format ( "Unknown variant type '%s' encountered", src.getType () ) ); } return result; }
Example #22
Source Project: ratebeer Author: erickok File: BarcodeSearchResultDeserializer.java License: GNU General Public License v3.0 | 5 votes |
@Override public BarcodeSearchResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject object = json.getAsJsonObject(); BarcodeSearchResult barcodeSearchResult = new BarcodeSearchResult(); barcodeSearchResult.beerId = object.get("BeerID").getAsInt(); barcodeSearchResult.beerName = Normalizer.get().cleanHtml(object.get("BeerName").getAsString()); barcodeSearchResult.brewerId = object.get("BrewerID").getAsInt(); barcodeSearchResult.brewerName = Normalizer.get().cleanHtml(object.get("BrewerName").getAsString()); if (!(object.get("AverageRating") instanceof JsonNull)) barcodeSearchResult.weightedRating = object.get("AverageRating").getAsFloat(); if (object.has("alcohol") && !(object.get("alcohol") instanceof JsonNull)) barcodeSearchResult.alcohol = object.get("alcohol").getAsFloat(); return barcodeSearchResult; }
Example #23
Source Project: ja-micro Author: Sixt File: JsonRpcRequestTest.java License: Apache License 2.0 | 5 votes |
@Test public void getIdAsString_NullJson_Null() { // given JsonRpcRequest req = new JsonRpcRequest(JsonNull.INSTANCE, "something", null); // when String result = req.getIdAsString(); // then assertThat(result).isNull(); }
Example #24
Source Project: ja-micro Author: Sixt File: JsonRpcResponseTest.java License: Apache License 2.0 | 5 votes |
@Test public void verifyToString() { JsonRpcResponse response = new JsonRpcResponse(new JsonPrimitive(42), JsonNull.INSTANCE, new JsonPrimitive("none"), 200); assertThat(response.getId()).isEqualTo(new JsonPrimitive(42)); assertThat(response.toString()).contains("[id=42,result=null,error=\"none\"]"); }
Example #25
Source Project: mapbox-plugins-android Author: mapbox File: Fill.java License: BSD 2-Clause "Simplified" License | 5 votes |
@Override void setUsedDataDrivenProperties() { if (!(jsonObject.get(FillOptions.PROPERTY_FILL_OPACITY) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(FillOptions.PROPERTY_FILL_OPACITY); } if (!(jsonObject.get(FillOptions.PROPERTY_FILL_COLOR) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(FillOptions.PROPERTY_FILL_COLOR); } if (!(jsonObject.get(FillOptions.PROPERTY_FILL_OUTLINE_COLOR) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(FillOptions.PROPERTY_FILL_OUTLINE_COLOR); } if (!(jsonObject.get(FillOptions.PROPERTY_FILL_PATTERN) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(FillOptions.PROPERTY_FILL_PATTERN); } }
Example #26
Source Project: mapbox-plugins-android Author: mapbox File: Line.java License: BSD 2-Clause "Simplified" License | 5 votes |
@Override void setUsedDataDrivenProperties() { if (!(jsonObject.get(LineOptions.PROPERTY_LINE_JOIN) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(LineOptions.PROPERTY_LINE_JOIN); } if (!(jsonObject.get(LineOptions.PROPERTY_LINE_OPACITY) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(LineOptions.PROPERTY_LINE_OPACITY); } if (!(jsonObject.get(LineOptions.PROPERTY_LINE_COLOR) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(LineOptions.PROPERTY_LINE_COLOR); } if (!(jsonObject.get(LineOptions.PROPERTY_LINE_WIDTH) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(LineOptions.PROPERTY_LINE_WIDTH); } if (!(jsonObject.get(LineOptions.PROPERTY_LINE_GAP_WIDTH) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(LineOptions.PROPERTY_LINE_GAP_WIDTH); } if (!(jsonObject.get(LineOptions.PROPERTY_LINE_OFFSET) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(LineOptions.PROPERTY_LINE_OFFSET); } if (!(jsonObject.get(LineOptions.PROPERTY_LINE_BLUR) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(LineOptions.PROPERTY_LINE_BLUR); } if (!(jsonObject.get(LineOptions.PROPERTY_LINE_PATTERN) instanceof JsonNull)) { annotationManager.enableDataDrivenProperty(LineOptions.PROPERTY_LINE_PATTERN); } }
Example #27
Source Project: letv Author: JackChan1999 File: TypeAdapters.java License: Apache License 2.0 | 5 votes |
public JsonElement read(JsonReader in) throws IOException { switch (in.peek()) { case NUMBER: return new JsonPrimitive(new LazilyParsedNumber(in.nextString())); case BOOLEAN: return new JsonPrimitive(Boolean.valueOf(in.nextBoolean())); case STRING: return new JsonPrimitive(in.nextString()); case NULL: in.nextNull(); return JsonNull.INSTANCE; case BEGIN_ARRAY: JsonElement array = new JsonArray(); in.beginArray(); while (in.hasNext()) { array.add(read(in)); } in.endArray(); return array; case BEGIN_OBJECT: JsonElement object = new JsonObject(); in.beginObject(); while (in.hasNext()) { object.add(in.nextName(), read(in)); } in.endObject(); return object; default: throw new IllegalArgumentException(); } }
Example #28
Source Project: matrix-java-sdk Author: kamax-matrix File: MatrixHttpClient.java License: GNU Affero General Public License v3.0 | 5 votes |
@Override public void deletePusher(String pushKey) { JsonObject pusher = new JsonObject(); pusher.add("kind", JsonNull.INSTANCE); pusher.addProperty("pushkey", pushKey); setPusher(pusher); }
Example #29
Source Project: rheem Author: rheem-ecosystem File: OperatorBase.java License: Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(Operator src, Type typeOfSrc, JsonSerializationContext context) { if (src == null) { return JsonNull.INSTANCE; } final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("_class", src.getClass().getName()); jsonObject.addProperty("name", src.getName()); return jsonObject; }
Example #30
Source Project: nomulus Author: google File: AbstractJsonableObject.java License: Apache License 2.0 | 5 votes |
/** Converts an Object to a JsonElement. */ private static JsonElement toJsonElement(String name, Member member, Object object) { if (object instanceof Jsonable) { Jsonable jsonable = (Jsonable) object; verifyAllowedJsonKeyName(name, member, jsonable.getClass()); return jsonable.toJson(); } if (object instanceof String) { return new JsonPrimitive((String) object); } if (object instanceof Number) { return new JsonPrimitive((Number) object); } if (object instanceof Boolean) { return new JsonPrimitive((Boolean) object); } if (object instanceof DateTime) { // According to RFC7483 section 3, the syntax of dates and times is defined in RFC3339. // // According to RFC3339, we should use ISO8601, which is what DateTime.toString does! return new JsonPrimitive(((DateTime) object).toString()); } if (object == null) { return JsonNull.INSTANCE; } throw new IllegalArgumentException( String.format( "Unknows object type '%s' in member '%s'", object.getClass(), member)); }