/** * <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); }
@Override public String encode(CodecRegistryProvider provider, boolean quoted) { return JSON.serialize(this.value); } }
@Override public void serialize(final Object obj, final StringBuilder buf) { JSON.string(buf, (String) obj); } }
static BasicDBObject convertToBasicDBObject(String object) { if (object == null || object.length() == 0) { return new BasicDBObject(); } else { return (BasicDBObject) JSON.parse(object); } }
@Override @SuppressWarnings("deprecation") public String toString() { return com.mongodb.util.JSON.serialize(this); }
@Override @SuppressWarnings("rawtypes") public void serialize(final Object obj, final StringBuilder buf) { boolean first = true; buf.append("{ "); Map m = (Map) obj; Entry entry; for (final Object o : m.entrySet()) { entry = (Entry) o; if (first) { first = false; } else { buf.append(" , "); } JSON.string(buf, entry.getKey().toString()); buf.append(" : "); serializer.serialize(entry.getValue(), buf); } buf.append("}"); }
/** * Returns a JSON serialization of this object * * @return JSON serialization */ @SuppressWarnings("deprecation") public String toString() { return com.mongodb.util.JSON.serialize(this); } }
@Override public void serialize(final Object obj, final StringBuilder buf) { boolean first = true; buf.append("{ "); DBObject dbo = (DBObject) obj; String name; for (final String s : dbo.keySet()) { name = s; if (first) { first = false; } else { buf.append(" , "); } JSON.string(buf, name); buf.append(" : "); serializer.serialize(dbo.get(name), buf); } buf.append("}"); }
/** * 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 JSON serialization of this object * * @return JSON serialization */ @SuppressWarnings("deprecation") public String toString() { return com.mongodb.util.JSON.serialize(this); } }
@Override public void serialize(final Object obj, final StringBuilder buf) { JSON.string(buf, (String) obj); } }
/** * 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; }
@Override public String toString() { return "Timestamp.BSON(ts=" + JSON.serialize(ts) + ")"; }
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."); }
private String getParameterWithIndex(List<Object> values, int index) { return JSON.serialize(values.get(index)); }
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(); }
/** * <p>Serializes an object into its JSON form.</p> * * <p>This method delegates serialization to {@code JSONSerializers.getLegacy}</p> * * @param object object to serialize * @return String containing JSON form of the object * @see JSONSerializers#getLegacy() */ public static String serialize(final Object object) { StringBuilder buf = new StringBuilder(); serialize(object, buf); return buf.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)); } }
@Override public void saveFields(XContentBuilder builder) throws IOException { builder.field(MongoDBRiver.LAST_TIMESTAMP_FIELD, JSON.serialize(ts)); } }