com.couchbase.client.java.document.json.JsonObjectからcom.google.gson.JsonObjectに変換する最良の方法は何ですか?その逆もあります。Google Base JsonObjectへのCouchbase JsonObjectとその逆?
0
A
答えて
0
現在、私は次のようにしています。
public RawJsonDocument put(final String key, final JsonObject googleJsonObject) {
return bucket.upsert(RawJsonDocument.create(key, googleJsonObject.toString()));
}
public String get(final String key) {
RawJsonDocument d = bucket.get(RawJsonDocument.create(key));
if (d != null) {
return d.content().toString();
}
return null;
}
参考:https://forums.couchbase.com/t/how-to-convert-a-java-object-to-jsonobject-type-of-couch-base/4255
0
別の方法があります。
public JsonDocument put(final String key, final JsonObject googleJsonObject) {
try {
JsonDocument document = JsonDocument.create(key,
com.couchbase.client.java.document.json.JsonObject.fromJson(googleJsonObject.toString()));
return bucket.upsert(document);
} catch (Throwable th) {
return null;
}
}
public String get(final String key) {
JsonDocument d = bucket.get(JsonDocument.create(key));
if (d != null) {
return d.content().toString();
} else {
return null;
}
}
しかし、RawJsonDocumentよりも遅いです。
ベンチマークモードのCNTスコアエラー単位
MyBenchmark.testJsonDocument 200 81285.574±1972.377オプスthrpt/sの MyBenchmark.testRawJsonDocument 200 148449.285±3639.312オプスthrpt/sの
0
別の方法 public JsonStringDocument put(final String key, final JsonObject googleJsonObject) { try { JsonStringDocument document = JsonStringDocument.create(key, googleJsonObject.toString()); return bucket.upsert(document); } catch (Throwable th) { return null; } }
public String get(final String key) {
JsonStringDocument d = bucket.get(JsonStringDocument.create(key));
if (d != null) {
return d.content().toString();
} else {
return null;
}
}
この1つはすべての3つの中で最高です。しかし、まだ私はより良い選択肢を探しています。
関連する問題
- 1. GoogleのカレンダーのJSONArrayとJSONObject
- 2. JsonObjectとJSONObjectの違い
- 3. JSONObjectからListView()へ
- 4. JSONObject
- 5. RESTクライアントでJsonObjectを逆シリアル化する
- 6. JSONObjectとJSONArray Swift
- 7. 1 JSONObjectとJSONArray
- 8. イテレータJsonObjectとJsonArray
- 9. Android JSONObjectとGSON
- 10. SpringのJSONObjectへのRequestbodyのマッピング
- 11. JsonObjectからBigDecimalへの値の変換
- 12. JSONObject []とJSONObjectの違いは何ですか?
- 13. JSONObject ClassNotFoundException
- 14. JSONObjectのJSONArrayのソート方法JSONObjectのフィールドに基づいてアルファベット
- 15. AndroidのデータベースはJSONObject
- 16. どのようJSONObject
- 17. マッピングリスト<Object>をJSONObjectのJSONObjectのRESTコール
- 18. org.jsonからJSONObjectからorg.codehaus.jacksonへ
- 19. 価値がJSONObject
- 20. JSONObject要素が
- 21. JSONObject not workingign
- 22. Androidスタジオ、JSONObject
- 23. JSONObjectを保存
- 24. JSONObject getString ifステートメント
- 25. org.json.simple.JSONObjectはJSONObject
- 26. 別のJsonObject間でJsonObjectを抽出します
- 27. android jsonObjectヌルポインタ例外
- 28. Gson JsonObjectグローバル変数
- 29. A JSONObjectテキストは、「{」エラー
- 30. Gson JsonObjectグローバル変数