com.mongodb.util.JSON.parse()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(188)

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

JSON.parse介绍

[英]Parses a JSON string and returns a corresponding Java object. The returned value is either a com.mongodb.DBObject(if the string is a JSON object or array), or a boxed primitive value according to the following mapping:

  • java.lang.Boolean for true or false
  • java.lang.Integer for integers between Integer.MIN_VALUE and Integer.MAX_VALUE
  • java.lang.Long for integers outside of this range
  • java.lang.Double for floating point numbers
    If the parameter is a string that contains a single-quoted or double-quoted string, it is returned as an unquoted java.lang.String. Parses a JSON string representing a JSON value
    [中]解析JSON字符串并返回相应的Java对象。返回的值可以是com。mongodb。DBObject(如果字符串是JSON对象或数组),或根据以下映射的装箱原语值:
    *爪哇。lang.Boolean表示真或假
    *爪哇。lang.Integer用于整数之间的整数。最小值和整数。最大值
    *爪哇。lang.Long表示超出此范围的整数
    *爪哇。lang.Double表示浮点数
    如果参数是一个包含单引号或双引号字符串的字符串,则它将作为无引号java返回。lang.String。解析表示JSON值的JSON字符串

代码示例

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * <p>Parses a JSON string and returns a corresponding Java object. The returned value is either a {@link com.mongodb.DBObject DBObject}
 * (if the string is a JSON object or array), or a boxed primitive value according to the following mapping:</p>
 * <ul>
 *     <li>{@code java.lang.Boolean} for {@code true} or {@code false}</li>
 *     <li>{@code java.lang.Integer} for integers between Integer.MIN_VALUE and Integer.MAX_VALUE</li>
 *     <li>{@code java.lang.Long} for integers outside of this range</li>
 *     <li>{@code java.lang.Double} for floating point numbers</li>
 * </ul>
 * If the parameter is a string that contains a single-quoted or double-quoted string, it is returned as an unquoted {@code
 * java.lang.String}. Parses a JSON string representing a JSON value
 *
 * @param jsonString the string to parse
 * @return a Java object representing the JSON data
 * @throws JSONParseException if jsonString is not valid JSON
 */
public static Object parse(final String jsonString) {
  return parse(jsonString, null);
}

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

static BasicDBObject convertToBasicDBObject(String object) {
  if (object == null || object.length() == 0) {
    return new BasicDBObject();
  } else {
    return (BasicDBObject) JSON.parse(object);
  }
}

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

timestamp = JSON.parse((String) timestamp);
  id = JSON.parse((String) id);

代码示例来源:origin: kaaproject/kaa

/**
 * Create new instance of <code>LogEvent</code>.
 *
 * @param dto           data transfer object, that contain id, header and event. use these data to
 *                      assign on appropriate field
 * @param clientProfile the client profile info
 * @param serverProfile the server profile info
 */
public LogEvent(LogEventDto dto, ProfileInfo clientProfile, ProfileInfo serverProfile) {
 this.id = dto.getId();
 this.header = encodeReservedCharacteres((DBObject) parse(dto.getHeader()));
 this.event = encodeReservedCharacteres((DBObject) parse(dto.getEvent()));
 this.clientProfile = (clientProfile != null)
   ? encodeReservedCharacteres((DBObject) parse(clientProfile.getBody())) : null;
 this.serverProfile = (serverProfile != null)
   ? encodeReservedCharacteres((DBObject) parse(serverProfile.getBody())) : null;
}

代码示例来源:origin: spring-projects/spring-data-mongodb

/**
 * Returns a list of {@link ParameterBinding}s found in the given {@code input} or an
 * {@link Collections#emptyList()}.
 *
 * @param input can be empty.
 * @param bindings must not be {@literal null}.
 * @return
 */
public String parseAndCollectParameterBindingsFromQueryIntoBindings(String input, List<ParameterBinding> bindings) {
  if (!StringUtils.hasText(input)) {
    return input;
  }
  Assert.notNull(bindings, "Parameter bindings must not be null!");
  String transformedInput = transformQueryAndCollectExpressionParametersIntoBindings(input, bindings);
  String parseableInput = makeParameterReferencesParseable(transformedInput);
  collectParameterReferencesIntoBindings(bindings,
      JSON.parse(parseableInput, new LenientPatternDecodingCallback()));
  return transformedInput;
}

代码示例来源:origin: kaaproject/kaa

public static void loadData() throws IOException {
 InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(DATA_FILE);
 BufferedReader reader = new BufferedReader(new InputStreamReader(input));
 String jsonLine = "";
 while ((jsonLine = reader.readLine()) != null) {
  if (StringUtils.isNotBlank(jsonLine)) {
   String currentLine = jsonLine.trim();
   if (jsonLine.startsWith(COLLECTION_NAME_LINE)) {
    setCollectionFromName(currentLine);
   } else {
    currentCollection.insert((DBObject) JSON.parse(jsonLine), WriteConcern.ACKNOWLEDGED);
   }
  }
 }
 input.close();
 LOG.info("Load data finished.");
}

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

static String addRemovePrefix(String prefix, String object, boolean add) {
  if (prefix == null) {
    throw new IllegalArgumentException("prefix");
  }
  if (object == null) {
    throw new NullPointerException("object");
  }
  if (object.length() == 0) {
    return "";
  }
  DBObject bsonObject = (DBObject) JSON.parse(object);
  BasicBSONObject newObject = new BasicBSONObject();
  for (String key : bsonObject.keySet()) {
    if (add) {
      newObject.put(prefix + key, bsonObject.get(key));
    } else {
      if (key.startsWith(prefix)) {
        newObject.put(key.substring(prefix.length()), bsonObject.get(key));
      } else {
        newObject.put(key, bsonObject.get(key));
      }
    }
  }
  return newObject.toString();
}

代码示例来源:origin: kaaproject/kaa

@Override
 public MongoEndpointProfile updateServerProfile(byte[] keyHash,
                         int version,
                         String serverProfile) {
  LOG.debug("Update server endpoint profile for endpoint with key hash {}, "
      + "schema version is {}",
    keyHash, version);
  updateFirst(
    query(where(EP_ENDPOINT_KEY_HASH).is(keyHash)),
    update(
      EP_SERVER_PROFILE_PROPERTY,
      MongoDaoUtil.encodeReservedCharacteres((DBObject) JSON.parse(serverProfile)))
      .set(EP_SERVER_PROFILE_VERSION_PROPERTY, version));
  return findById(ByteBuffer.wrap(keyHash));
 }
}

代码示例来源:origin: spring-projects/spring-data-mongodb

BasicQuery result = new BasicQuery(query.getQueryObject(), new Document((BasicDBObject) JSON.parse(fieldSpec)));
result.setSortObject(query.getSortObject());

代码示例来源:origin: dboissier/mongo4idea

public void setOperations(String aggregateQuery) {
  operations.clear();
  BasicDBList operations = (BasicDBList) JSON.parse(aggregateQuery);
  for (Object operation1 : operations) {
    BasicDBObject operation = (BasicDBObject) operation1;
    this.operations.add(operation);
  }
}

代码示例来源:origin: apache/nifi

? Document.parse(new String(content, charset)) : JSON.parse(new String(content, charset));

代码示例来源:origin: debezium/debezium

VerifyRecord.isValid(record);
Struct key = (Struct) record.key();
ObjectId id = (ObjectId)(JSON.parse(key.getString("id")));
foundIds.add(id);
if (record.value() != null) {

代码示例来源:origin: kaaproject/kaa

this.epsConfigurationHash = dto.getEpsConfigurationHash();
this.profile = MongoDaoUtil.encodeReservedCharacteres(
  (DBObject) JSON.parse(dto.getClientProfileBody()));
this.profileHash = dto.getProfileHash();
this.profileVersion = dto.getClientProfileVersion();
this.sdkToken = dto.getSdkToken();
this.serverProfile = MongoDaoUtil.encodeReservedCharacteres(
  (DBObject) JSON.parse(dto.getServerProfileBody()));
this.useConfigurationRawSchema = dto.isUseConfigurationRawSchema();
this.version = dto.getVersion();

代码示例来源:origin: geotools/geotools

@Override
public SimpleFeatureType retrieveSchema(Name name) throws IOException {
  if (name == null) {
    return null;
  }
  File schemaFile = schemaFile(name);
  if (!schemaFile.canRead()) {
    return null;
  }
  BufferedReader reader = new BufferedReader(new FileReader(schemaFile));
  try {
    String lineSeparator = System.getProperty("line.separator");
    StringBuilder jsonBuilder = new StringBuilder();
    String line;
    while ((line = reader.readLine()) != null) {
      jsonBuilder.append(line);
      jsonBuilder.append(lineSeparator);
    }
    Object o = JSON.parse(jsonBuilder.toString());
    if (o instanceof DBObject) {
      return FeatureTypeDBObject.convert((DBObject) o, name);
    }
  } finally {
    reader.close();
  }
  return null;
}

代码示例来源:origin: dboissier/mongo4idea

@Override
public void validateQuery() {
  try {
    String query = getQuery();
    if (StringUtils.isEmpty(query)) {
      return;
    }
    JSON.parse(query);
  } catch (JSONParseException | NumberFormatException ex) {
    notifyOnErrorForOperator(editor.getComponent(), ex);
  }
}

代码示例来源:origin: dboissier/mongo4idea

private void validateEditorQuery(Editor editor) {
  try {
    String query = getQueryFrom(editor);
    if (StringUtils.isEmpty(query)) {
      return;
    }
    JSON.parse(query);
  } catch (JSONParseException | NumberFormatException ex) {
    notifyOnErrorForOperator(editor.getComponent(), ex);
  }
}

代码示例来源:origin: Impetus/Kundera

/**
 * Parses the and scroll.
 * 
 * @param jsonClause
 *            the json clause
 * @param collectionName
 *            the collection name
 * @return the DB cursor
 * @throws JSONParseException
 *             the JSON parse exception
 */
private DBCursor parseAndScroll(String jsonClause, String collectionName) throws JSONParseException
{
  BasicDBObject clause = (BasicDBObject) JSON.parse(jsonClause);
  DBCursor cursor = mongoDb.getCollection(collectionName).find(clause);
  return cursor;
}

代码示例来源:origin: debezium/debezium

Struct insertKey = (Struct)insertRecord.key();
Struct updateKey = (Struct)updateRecord.key();
String insertId = JSON.parse(insertKey.getString("id")).toString();
String updateId = JSON.parse(updateKey.getString("id")).toString();
assertThat(insertId).isEqualTo(id.get());
assertThat(updateId).isEqualTo(id.get());

代码示例来源:origin: org.springframework.data/spring-data-mongodb

/**
 * Returns a list of {@link ParameterBinding}s found in the given {@code input} or an
 * {@link Collections#emptyList()}.
 *
 * @param input can be empty.
 * @param bindings must not be {@literal null}.
 * @return
 */
public String parseAndCollectParameterBindingsFromQueryIntoBindings(String input, List<ParameterBinding> bindings) {
  if (!StringUtils.hasText(input)) {
    return input;
  }
  Assert.notNull(bindings, "Parameter bindings must not be null!");
  String transformedInput = transformQueryAndCollectExpressionParametersIntoBindings(input, bindings);
  String parseableInput = makeParameterReferencesParseable(transformedInput);
  collectParameterReferencesIntoBindings(bindings,
      JSON.parse(parseableInput, new LenientPatternDecodingCallback()));
  return transformedInput;
}

代码示例来源:origin: Impetus/Kundera

/**
 * Generate bson from java object.
 * 
 * @param obj
 *            the obj
 * @return the BSON object
 */
protected BSONObject generateBSONFromJavaObject(Object obj)
{
  ObjectWriter ow = new ObjectMapper().writer();
  String json = null;
  try
  {
    json = ow.writeValueAsString(obj);
    return (BSONObject) JSON.parse(json);
  }
  catch (JsonGenerationException | JsonMappingException e)
  {
    throw new KunderaException(
        "Error in converting BSON Object from Java Object due to error in JSON generation/mapping. Caused BY:",
        e);
  }
  catch (IOException e)
  {
    throw new KunderaException("Error in converting BSON Object from Java Object. Caused BY:", e);
  }
}

相关文章

微信公众号

最新文章

更多