本文整理了Java中com.mongodb.util.JSON.parse()
方法的一些代码示例,展示了JSON.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON.parse()
方法的具体详情如下:
包路径:com.mongodb.util.JSON
类名称: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:
代码示例来源: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);
}
}
内容来源于网络,如有侵权,请联系作者删除!