本文整理了Java中com.mongodb.util.JSON
类的一些代码示例,展示了JSON
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON
类的具体详情如下:
包路径:com.mongodb.util.JSON
类名称:JSON
[英]Helper methods for JSON serialization and de-serialization
[中]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: spring-projects/spring-data-mongodb
@Override
public String encode(CodecRegistryProvider provider, boolean quoted) {
return JSON.serialize(this.value);
}
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public void serialize(final Object obj, final StringBuilder buf) {
JSON.string(buf, (String) obj);
}
}
代码示例来源: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: org.mongodb/mongo-java-driver
@Override
@SuppressWarnings("deprecation")
public String toString() {
return com.mongodb.util.JSON.serialize(this);
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@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("}");
}
代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb
timestamp = JSON.parse((String) timestamp);
id = JSON.parse((String) id);
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* Returns a JSON serialization of this object
*
* @return JSON serialization
*/
@SuppressWarnings("deprecation")
public String toString() {
return com.mongodb.util.JSON.serialize(this);
}
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@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("}");
}
代码示例来源: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: org.mongodb/mongo-java-driver
/**
* Returns a JSON serialization of this object
*
* @return JSON serialization
*/
@SuppressWarnings("deprecation")
public String toString() {
return com.mongodb.util.JSON.serialize(this);
}
}
代码示例来源:origin: org.mongodb/mongodb-driver
@Override
public void serialize(final Object obj, final StringBuilder buf) {
JSON.string(buf, (String) obj);
}
}
代码示例来源: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: richardwilly98/elasticsearch-river-mongodb
@Override
public String toString() {
return "Timestamp.BSON(ts=" + JSON.serialize(ts) + ")";
}
代码示例来源: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: spring-projects/spring-batch
private String getParameterWithIndex(List<Object> values, int index) {
return JSON.serialize(values.get(index));
}
代码示例来源: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: org.mongodb/mongo-java-driver
/**
* <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();
}
代码示例来源: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: richardwilly98/elasticsearch-river-mongodb
@Override
public void saveFields(XContentBuilder builder) throws IOException {
builder.field(MongoDBRiver.LAST_TIMESTAMP_FIELD, JSON.serialize(ts));
}
}
内容来源于网络,如有侵权,请联系作者删除!