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 File: ConfigUtils.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #2
Source File: FormattedMessageWriter.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
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 File: ILoggingEventSerializer.java    From twill with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: ModulesConfig.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #5
Source File: PlaceSearchResultDeserializer.java    From ratebeer with GNU General Public License v3.0 6 votes vote down vote up
@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 #6
Source File: BeerSearchResultDeserializer.java    From ratebeer with GNU General Public License v3.0 6 votes vote down vote up
@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 #7
Source File: BeerOnTopListDeserializer.java    From ratebeer with GNU General Public License v3.0 6 votes vote down vote up
@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 #8
Source File: DateSerializer.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #9
Source File: Streams.java    From letv with Apache License 2.0 6 votes vote down vote up
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 File: Circle.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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 #11
Source File: DiagnosticsNode.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean getBooleanMember(String memberName, boolean defaultValue) {
  if (!json.has(memberName)) {
    return defaultValue;
  }
  final JsonElement value = json.get(memberName);
  if (value instanceof JsonNull) {
    return defaultValue;
  }
  return value.getAsBoolean();
}
 
Example #12
Source File: DiagnosticsNode.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private DiagnosticsTreeStyle getStyleMember(String memberName, DiagnosticsTreeStyle defaultValue) {
  if (!json.has(memberName)) {
    return defaultValue;
  }
  final JsonElement value = json.get(memberName);
  if (value instanceof JsonNull) {
    return defaultValue;
  }
  return DiagnosticsTreeStyle.valueOf(value.getAsString());
}
 
Example #13
Source File: DiagnosticsNode.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private DiagnosticsTreeStyle getStyleMember(String memberName, DiagnosticsTreeStyle defaultValue) {
  if (!json.has(memberName)) {
    return defaultValue;
  }
  final JsonElement value = json.get(memberName);
  if (value instanceof JsonNull) {
    return defaultValue;
  }
  return DiagnosticsTreeStyle.valueOf(value.getAsString());
}
 
Example #14
Source File: MetaDataResolver.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static String sampleBarcodeP5(@NotNull JsonObject metadata, @NotNull String objectName) {
    JsonObject object = metadata.getAsJsonObject(objectName);
    if (object == null) {
        return null;
    }
    JsonElement sampleBarcodeId = object.get("sampleId");
    return sampleBarcodeId != null && !(sampleBarcodeId instanceof JsonNull) ? sampleBarcodeId.getAsString() : null;
}
 
Example #15
Source File: DiagnosticsNode.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private DiagnosticLevel getLevelMember(String memberName, DiagnosticLevel defaultValue) {
  if (!json.has(memberName)) {
    return defaultValue;
  }
  final JsonElement value = json.get(memberName);
  if (value instanceof JsonNull) {
    return defaultValue;
  }
  try {
    return DiagnosticLevel.valueOf(value.getAsString());
  }
  catch (IllegalArgumentException ignore) {
    return defaultValue;
  }
}
 
Example #16
Source File: DiagnosticsNode.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean getBooleanMember(String memberName, boolean defaultValue) {
  if (!json.has(memberName)) {
    return defaultValue;
  }
  final JsonElement value = json.get(memberName);
  if (value instanceof JsonNull) {
    return defaultValue;
  }
  return value.getAsBoolean();
}
 
Example #17
Source File: CustomGsonConverterFactory.java    From JianshuApp with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public T convert(ResponseBody value) throws IOException {
    if (type.getRawType().equals(String.class)) {
        return (T) value.string();
    }

    JsonElement jsonElement = null;
    T result;
    try {
        // 解析错误时可获取原始JSON
        jsonElement = gson.fromJson(value.charStream(), JsonElement.class);
        if (jsonElement == null) {
            jsonElement = JsonNull.INSTANCE;
        }
        result = adapter.fromJsonTree(jsonElement);
        if (result == null) {
            try {
                result = adapter.fromJson("{}");
            } catch (Exception ignored) {
            }
        }
    } catch (JsonSyntaxException e) {
        throw new JsonParserException(jsonElement, e.getMessage());
    } finally {
        value.close();
    }
    return result;
}
 
Example #18
Source File: JSON.java    From nifi-api-client-java with Apache License 2.0 5 votes vote down vote up
/**
 * Serialize
 *
 * @param src Date
 * @param typeOfSrc Type
 * @param context Json Serialization Context
 * @return Json Element
 */
@Override
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
    if (src == null) {
        return JsonNull.INSTANCE;
    } else {
        return new JsonPrimitive(apiClient.formatDatetime(src));
    }
}
 
Example #19
Source File: BeerDetailsDeserializer.java    From ratebeer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BeerDetails deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
	JsonObject object = json.getAsJsonObject();
	BeerDetails beerDetails = new BeerDetails();
	beerDetails.beerId = object.get("BeerID").getAsInt();
	beerDetails.beerName = Normalizer.get().cleanHtml(object.get("BeerName").getAsString());
	beerDetails.brewerId = object.get("BrewerID").getAsInt();
	beerDetails.brewerName = Normalizer.get().cleanHtml(object.get("BrewerName").getAsString());
	beerDetails.brewerCountryId = object.get("BrewerCountryID").getAsInt();
	beerDetails.styleId = object.get("BeerStyleID").getAsInt();
	beerDetails.styleName= Normalizer.get().cleanHtml(object.get("BeerStyleName").getAsString());

	if (!(object.get("OverallPctl") instanceof JsonNull))
		beerDetails.overallPercentile = object.get("OverallPctl").getAsFloat();
	if (!(object.get("StylePctl") instanceof JsonNull))
		beerDetails.stylePercentile = object.get("StylePctl").getAsFloat();
	if (!(object.get("RealAverage") instanceof JsonNull))
		beerDetails.realRating = object.get("RealAverage").getAsFloat();
	if (!(object.get("AverageRating") instanceof JsonNull))
		beerDetails.weightedRating = object.get("AverageRating").getAsFloat();
	beerDetails.rateCount = object.get("RateCount").getAsInt();

	beerDetails.alcohol = object.get("Alcohol").getAsFloat();
	if (!(object.get("IBU") instanceof JsonNull))
		beerDetails.ibu = object.get("IBU").getAsFloat();
	beerDetails.alias = object.get("IsAlias").getAsBoolean();
	beerDetails.description = Normalizer.get().cleanHtml(object.get("Description").getAsString());

	return beerDetails;
}
 
Example #20
Source File: AbstractJsonableObject.java    From nomulus with Apache License 2.0 5 votes vote down vote up
/** 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));
}
 
Example #21
Source File: GenericJsonEvent.java    From bender with Apache License 2.0 5 votes vote down vote up
@Override
public Object getField(String field) throws FieldNotFoundException {
  if (this.payload == null) {
    throw new FieldNotFoundException(field + " is not in payload because payload is null");
  }

  JsonObject json = this.payload.getAsJsonObject();
  Object obj;
  try {
    obj = JsonPathProvider.read(json, field);
  } catch(InvalidPathException e) {
    throw new FieldNotFoundException("Field cannot be found because " + field
        + " is an invalid path");
  }

  if (obj == null || obj instanceof JsonNull) {
    throw new FieldNotFoundException(field + " is not in payload.");
  }

  if (obj instanceof JsonPrimitive) {
    if (((JsonPrimitive) obj).isString()) {
      return ((JsonPrimitive) obj).getAsString();
    }
  }

  return obj;
}
 
Example #22
Source File: OperatorBase.java    From rheem with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: GsonScalars.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
private static JsonElement parseJsonValue(Value value) {
    if (value instanceof BooleanValue) {
        return new JsonPrimitive(((BooleanValue) value).isValue());
    }
    if (value instanceof EnumValue) {
        return new JsonPrimitive(((EnumValue) value).getName());
    }
    if (value instanceof FloatValue) {
        return new JsonPrimitive(((FloatValue) value).getValue());
    }
    if (value instanceof IntValue) {
        return new JsonPrimitive(((IntValue) value).getValue());
    }
    if (value instanceof NullValue) {
        return JsonNull.INSTANCE;
    }
    if (value instanceof StringValue) {
        return new JsonPrimitive(((StringValue) value).getValue());
    }
    if (value instanceof ArrayValue) {
        List<Value> values = ((ArrayValue) value).getValues();
        JsonArray jsonArray = new JsonArray(values.size());
        values.forEach(v -> jsonArray.add(parseJsonValue(v)));
        return jsonArray;
    }
    if (value instanceof ObjectValue) {
        final JsonObject result = new JsonObject();
        ((ObjectValue) value).getObjectFields().forEach(objectField ->
                result.add(objectField.getName(), parseJsonValue(objectField.getValue())));
        return result;
    }
    //Should never happen, as it would mean the variable was not replaced by the parser
    throw new CoercingParseLiteralException("Unknown scalar AST type: " + value.getClass().getName());
}
 
Example #24
Source File: MatrixHttpClient.java    From matrix-java-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void deletePusher(String pushKey) {
    JsonObject pusher = new JsonObject();
    pusher.add("kind", JsonNull.INSTANCE);
    pusher.addProperty("pushkey", pushKey);
    setPusher(pusher);
}
 
Example #25
Source File: TypeAdapters.java    From letv with Apache License 2.0 5 votes vote down vote up
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 #26
Source File: GsonRuntime.java    From jmespath-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private JsonElement nodeOrNullNode(JsonElement node) {
  if (node == null) {
    return JsonNull.INSTANCE;
  } else {
    return node;
  }
}
 
Example #27
Source File: Line.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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 #28
Source File: BreweryDetailsDeserializer.java    From ratebeer with GNU General Public License v3.0 5 votes vote down vote up
@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 #29
Source File: BreweryBeerDeserializer.java    From ratebeer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BreweryBeer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
	JsonObject object = json.getAsJsonObject();
	BreweryBeer breweryBeer = new BreweryBeer();

	breweryBeer.beerId = object.get("BeerID").getAsInt();
	breweryBeer.beerName = Normalizer.get().cleanHtml(object.get("BeerName").getAsString());
	breweryBeer.brewerId = object.get("BrewerID").getAsInt();
	breweryBeer.brewerName = Normalizer.get().cleanHtml(object.get("BrewerName").getAsString());
	if (!(object.get("ContractBrewerID") instanceof JsonNull))
		breweryBeer.contractId = object.get("ContractBrewerID").getAsLong();
	if (!(object.get("ContractBrewer") instanceof JsonNull))
		breweryBeer.contractName = Normalizer.get().cleanHtml(object.get("ContractBrewer").getAsString());
	breweryBeer.styleId = object.get("BeerStyleID").getAsInt();
	breweryBeer.styleName = Normalizer.get().cleanHtml(object.get("BeerStyleName").getAsString());

	if (!(object.get("OverallPctl") instanceof JsonNull))
		breweryBeer.overallPercentile = object.get("OverallPctl").getAsFloat();
	if (!(object.get("StylePctl") instanceof JsonNull))
		breweryBeer.stylePercentile = object.get("StylePctl").getAsFloat();
	if (!(object.get("AverageRating") instanceof JsonNull))
		breweryBeer.weightedRating = object.get("AverageRating").getAsFloat();
	breweryBeer.rateCount = object.get("RateCount").getAsInt();

	breweryBeer.alcohol = object.get("Alcohol").getAsFloat();
	if (object.has("IsAlias") && !(object.get("IsAlias") instanceof JsonNull))
		breweryBeer.alias = object.get("IsAlias").getAsBoolean();
	if (object.has("Retired") && !(object.get("Retired") instanceof JsonNull))
		breweryBeer.retired = object.get("Retired").getAsBoolean();
	if (!(object.get("UserHadIt") instanceof JsonNull))
		breweryBeer.ratedByUser = object.get("UserHadIt").getAsInt() == 1;
	if (!(object.get("UserRating") instanceof JsonNull))
		breweryBeer.ratingOfUser = object.get("UserRating").getAsFloat();

	return breweryBeer;
}
 
Example #30
Source File: GsonUtils.java    From mina with Apache License 2.0 5 votes vote down vote up
/**
 * @param src :将要被转化的对象
 * @return :转化后的JSON串
 * @MethodName : toJson
 * @Description : 将对象转为JSON串,此方法能够满足大部分需求
 */
public static String toJson(Object src) {
    if (src == null) {
        return gson.toJson(JsonNull.INSTANCE);
    }
    return gson.toJson(src);
}