elemental.json.Json.createNull()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中elemental.json.Json.createNull()方法的一些代码示例,展示了Json.createNull()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.createNull()方法的具体详情如下:
包路径:elemental.json.Json
类名称:Json
方法名:createNull

Json.createNull介绍

暂无

代码示例

代码示例来源:origin: com.vaadin/vaadin-server

private void putValueOrNull(JsonObject object, String key, String value) {
    assert object != null;
    assert key != null;
    if (value == null) {
      object.put(key, Json.createNull());
    } else {
      object.put(key, value);
    }
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

private static void putValueOrJsonNull(JsonObject json, String key,
    String value) {
  if (value == null) {
    json.put(key, Json.createNull());
  } else {
    json.put(key, value);
  }
}

代码示例来源:origin: com.vaadin/vaadin-testbench-core

private JsonValue createJsonValue(Object value) {
  if (value == null) {
    return Json.createNull();
  } else if (value instanceof String) {
    return Json.create((String) value);
  } else if (value instanceof Number) {
    return Json.create(((Number) value).doubleValue());
  } else if (value instanceof Boolean) {
    return Json.create((Boolean) value);
  } else {
    throw new IllegalArgumentException(
        "Type of property is unsupported: "
            + value.getClass().getName());
  }
}

代码示例来源:origin: com.vaadin/hummingbird-server

private static void putValueOrJsonNull(JsonObject json, String key,
    String value) {
  if (value == null) {
    json.put(key, Json.createNull());
  } else {
    json.put(key, value);
  }
}

代码示例来源:origin: com.vaadin/flow-server

private static void putValueOrJsonNull(JsonObject json, String key,
    String value) {
  if (value == null) {
    json.put(key, Json.createNull());
  } else {
    json.put(key, value);
  }
}

代码示例来源:origin: com.vaadin/flow-server

private static void putValueOrNull(JsonObject object, String key,
    String value) {
  assert object != null;
  assert key != null;
  if (value == null) {
    object.put(key, Json.createNull());
  } else {
    object.put(key, value);
  }
}

代码示例来源:origin: com.vaadin/hummingbird-server

private static void putValueOrNull(JsonObject object, String key,
    String value) {
  assert object != null;
  assert key != null;
  if (value == null) {
    object.put(key, Json.createNull());
  } else {
    object.put(key, value);
  }
}

代码示例来源:origin: com.vaadin/hummingbird-server

/**
 * Helper for encoding any "primitive" value that is directly supported in
 * JSON. Supported values types are {@link String}, {@link Number},
 * {@link Boolean}, {@link JsonValue}. <code>null</code> is also supported.
 *
 * @param value
 *            the value to encode
 * @return the value encoded as JSON
 */
public static JsonValue encodeWithoutTypeInfo(Object value) {
  if (value == null) {
    return Json.createNull();
  }
  Class<?> type = value.getClass();
  if (String.class.equals(value.getClass())) {
    return Json.create((String) value);
  } else if (Integer.class.equals(type) || Double.class.equals(type)) {
    return Json.create(((Number) value).doubleValue());
  } else if (Boolean.class.equals(type)) {
    return Json.create(((Boolean) value).booleanValue());
  } else if (JsonValue.class.isAssignableFrom(type)) {
    return (JsonValue) value;
  }
  assert !canEncodeWithoutTypeInfo(type);
  throw new IllegalArgumentException(
      "Can't encode" + value.getClass() + " to json");
}

代码示例来源:origin: com.vaadin/flow-server

/**
 * Helper for encoding any "primitive" value that is directly supported in
 * JSON. Supported values types are {@link String}, {@link Number},
 * {@link Boolean}, {@link JsonValue}. <code>null</code> is also supported.
 *
 * @param value
 *            the value to encode
 * @return the value encoded as JSON
 */
public static JsonValue encodeWithoutTypeInfo(Object value) {
  if (value == null) {
    return Json.createNull();
  }
  Class<?> type = value.getClass();
  if (String.class.equals(value.getClass())) {
    return Json.create((String) value);
  } else if (Integer.class.equals(type) || Double.class.equals(type)) {
    return Json.create(((Number) value).doubleValue());
  } else if (Boolean.class.equals(type)) {
    return Json.create(((Boolean) value).booleanValue());
  } else if (JsonValue.class.isAssignableFrom(type)) {
    return (JsonValue) value;
  }
  assert !canEncodeWithoutTypeInfo(type);
  throw new IllegalArgumentException(
      "Can't encode " + value.getClass() + " to json");
}

代码示例来源:origin: com.googlecode.gwtquery/gwtquery

private Object setValue(JsonArray jsArr, JsonObject jsObj, String attr, Object val) {
 if (val == null) {
  return Json.createNull();

代码示例来源:origin: com.vaadin/flow-server

return Json.createNull();

代码示例来源:origin: com.vaadin/flow-server

/**
 * Creates a list of data objects which can be passed to the constructor
 * returned by {@link #getEventConstructor(Class)} as parameters 3+.
 *
 * @param domEvent
 *            the DOM event containing the data
 * @param eventType
 *            the component event type
 * @return a list of event data objects in the same order as defined in the
 *         component event constructor
 */
private List<Object> createEventDataObjects(DomEvent domEvent,
    Class<? extends ComponentEvent<?>> eventType) {
  List<Object> eventDataObjects = new ArrayList<>();
  LinkedHashMap<String, Class<?>> expressions = ComponentEventBusUtil
      .getEventDataExpressions(eventType);
  expressions.forEach((expression, type) -> {
    JsonValue jsonValue = domEvent.getEventData().get(expression);
    if (jsonValue == null) {
      jsonValue = Json.createNull();
    }
    Object value = JsonCodec.decodeAs(jsonValue, type);
    eventDataObjects.add(value);
  });
  return eventDataObjects;
}

代码示例来源:origin: com.vaadin/flow-server

private static JsonValue encodeNode(Node<?> node) {
  StateNode stateNode = node.getNode();
  if (stateNode.isAttached()) {
    return wrapComplexValue(NODE_TYPE, Json.create(stateNode.getId()));
  } else {
    return Json.createNull();
  }
}

代码示例来源:origin: com.vaadin/hummingbird-server

private static JsonValue encodeElement(Element element) {
  StateNode node = element.getNode();
  if (node.isAttached()) {
    return wrapComplexValue(ELEMENT_TYPE, Json.create(node.getId()));
  } else {
    return Json.createNull();
  }
}

相关文章

微信公众号

最新文章

更多