/** * <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); }
static BasicDBObject convertToBasicDBObject(String object) { if (object == null || object.length() == 0) { return new BasicDBObject(); } else { return (BasicDBObject) JSON.parse(object); } }
/** * 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; }
/** * 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; }
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."); }
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(); }
@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)); } }
BasicQuery result = new BasicQuery(query.getQueryObject(), new Document((BasicDBObject) JSON.parse(fieldSpec))); result.setSortObject(query.getSortObject());
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); } }
? Document.parse(new String(content, charset)) : JSON.parse(new String(content, charset));
VerifyRecord.isValid(record); Struct key = (Struct) record.key(); ObjectId id = (ObjectId)(JSON.parse(key.getString("id"))); foundIds.add(id); if (record.value() != null) {
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();
@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; }
@Override public void validateQuery() { try { String query = getQuery(); if (StringUtils.isEmpty(query)) { return; } JSON.parse(query); } catch (JSONParseException | NumberFormatException ex) { notifyOnErrorForOperator(editor.getComponent(), ex); } }
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); } }
/** * 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; }
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());
/** * 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; }
/** * 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); } }