本文整理汇总了Java中com.couchbase.client.java.document.json.JsonObject.put方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.put方法的具体用法?Java JsonObject.put怎么用?Java JsonObject.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.couchbase.client.java.document.json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.put方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: searchDevelopers
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
@ResponseBody
@RequestMapping("/developer/search")
public String searchDevelopers(final @RequestParam("firstname") String firstName, final @RequestParam("lastname") String lastName) throws Exception {
String statement = "SELECT developer.* FROM `" + bucket.name() + "` AS developer WHERE developer.type = 'developer'";
JsonObject params = JsonObject.create();
if (!firstName.equals("")) {
params.put("firstName", firstName.toLowerCase() + "%");
statement += " AND lower(developer.developerInfo.firstName) LIKE $firstName";
}
if (!lastName.equals("")) {
params.put("lastName", lastName.toLowerCase() + "%");
statement += " AND lower(developer.developerInfo.lastName) LIKE $lastName";
}
N1qlQuery developerByEmail = N1qlQuery.parameterized(statement, params);
return rawQueryExecutor.n1qlToRawJson(developerByEmail);
}
示例2: upsert
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
@Override
public Tt upsert(Tt tt) {
JsonObject content = JsonObject.fromJson(gson.toJson(tt));
content.put(DOCTYPE_KEY, DOCTYPE_TT);
Document<?> document = JsonDocument.create(tt.getId().toString(), content);
bucket.upsert(document);
return tt;
}
示例3: toJsonObject
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
/**
*
* @param obj an array of pairs of property name and value, or Map<String, Object>, or an entity with getter/setter methods.
* @return
*/
public static JsonObject toJsonObject(final Object obj) {
Map<String, Object> m = null;
if (obj instanceof Map) {
m = (Map<String, Object>) obj;
} else if (N.isEntity(obj.getClass())) {
m = Maps.entity2Map(obj);
} else if (obj instanceof Object[]) {
m = N.asProps(obj);
} else {
throw new IllegalArgumentException("The parameters must be a Map, or an entity class with getter/setter methods");
}
final JsonObject result = JsonObject.create();
for (Map.Entry<String, Object> entry : m.entrySet()) {
if (entry.getValue() == null || supportedTypes.contains(entry.getValue().getClass())) {
result.put(entry.getKey(), entry.getValue());
} else {
Type<Object> valueType = N.typeOf(entry.getValue().getClass());
if (valueType.isMap() || valueType.isEntity()) {
result.put(entry.getKey(), toJsonObject(entry.getValue()));
} else if (valueType.isObjectArray() || valueType.isCollection()) {
result.put(entry.getKey(), toJsonArray(entry.getValue()));
} else {
result.put(entry.getKey(), N.stringOf(entry.getValue()));
}
}
}
return result;
}
示例4: mapRow
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
public JsonDocument mapRow(ResultSet rs, int rowNum) throws SQLException {
String id = table.getName() + "::" + rs.getString(table.getPrimaryKey());
JsonObject obj = JsonObject.create();
for (Column col : table.getColumns()) {
Object value = getJsonTypedValue(col.type, rs.getObject(col.name), col.name);
obj.put(col.name, value);
}
return JsonDocument.create(id, obj);
}
示例5: getJsonTypedValue
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
public Object getJsonTypedValue(int type, Object value, String name) throws SQLException {
if (value == null) {
return null;
}
JDBCType current = JDBCType.valueOf(type);
switch (current) {
case TIMESTAMP:
Timestamp timestamp = (Timestamp) value;
return timestamp.getTime();
case TIMESTAMP_WITH_TIMEZONE:
Timestamp ts = (Timestamp) value;
JsonObject tsWithTz = JsonObject.create();
tsWithTz.put("timestamp", ts.getTime());
tsWithTz.put("timezone", ts.getTimezoneOffset());
return tsWithTz;
case DATE:
Date sqlDate = (Date) value;
return sqlDate.getTime();
case DECIMAL:
case NUMERIC:
BigDecimal bigDecimal = (BigDecimal) value;
return bigDecimal.doubleValue();
case ARRAY:
Array array = (Array) value;
Object[] objects = (Object[]) array.getArray();
return JsonArray.from(objects);
case BINARY:
case BLOB:
case LONGVARBINARY:
return Base64.getEncoder().encodeToString((byte[]) value);
case OTHER:
case JAVA_OBJECT:
// database specific, default to String value
return value.toString();
default:
return value;
}
}
示例6: toJsonObject
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
public JsonObject toJsonObject() {
JsonObject obj = JsonObject.create();
JsonArray jsonColumns = JsonArray.create();
for (Column col : columns) {
jsonColumns.add(col.toJsonObject());
}
obj.put("tableName", name);
obj.put("primaryKey", primaryKey);
obj.put("columns", jsonColumns);
return obj;
}
示例7: save
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
@Override
public void save(final Session session) {
JsonObject json = JsonObject.from(session.attributes());
// session metadata
json.put("_accessedAt", session.accessedAt());
json.put("_createdAt", session.createdAt());
json.put("_savedAt", session.savedAt());
JsonDocument doc = JsonDocument.create(N1Q.qualifyId(SESSION, session.id()), expiry, json);
bucket.upsert(doc);
}
示例8: createNode
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
private JsonObject createNode(final String status, final String nodeName) {
final JsonObject node1 = JsonObject.create();
node1.put("status", status);
node1.put("hostname", nodeName);
return node1;
}
示例9: convertMap
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
private static JsonObject convertMap(final MapType map) throws XPathException {
final JsonObject jo = JsonValue.jo();
// Get all keys
final Sequence keys = map.keys();
// Iterate over all keys
for (final SequenceIterator i = keys.iterate(); i.hasNext(); ) {
// Get next item
final Item key = i.nextItem();
// Only use Strings as key, as required by JMS
final String keyValue = key.getStringValue();
// Get values
final Sequence sequence = map.get((AtomicValue) key);
jo.put(keyValue, convertSequence(sequence));
}
return jo;
}