JSON オブジェクトから BLOB 列を削除したいと考えています。オブジェクトのいずれかに "@type": "blob" があるかどうかを確認する必要があります。列全体を削除する必要があります。元。以下はDBからのレコードです。'experience'、'hitpoints'、'name'、'uuid'、'image' (オプション) が列です。レコードにはブロブ列、つまり画像があるためです。ドロップする必要があります。
サンプル I/P:
{
"experience": 14248,
"hitpoints": 9223372036854775807,
"name": "Aaron1",
"uuid": "78edf902-7dd2-49a4-99b4-1c94ee286a33",
"image": {
"@type": "blob",
"content_type": "image/jpeg",
"digest": "sha1–4xlj1AKFgLdzcD7a1pVChrVTJIc=",
"length": 3888349
}
},
{
"experience": 14252,
"hitpoints": 92233720368512345,
"name": "Aaron2",
"uuid": "78edf902-7dd2-49a4-99b4-1a94ff286a45",
}
サンプル O/P:
{
"experience": 14248,
"hitpoints": 9223372036854775807,
"name": "Aaron1",
"uuid": "78edf902-7dd2-49a4-99b4-1c94ee286a33",
},
{
"experience": 14252,
"hitpoints": 92233720368512345,
"name": "Aaron2",
"uuid": "78edf902-7dd2-49a4-99b4-1a94ff286a45",
}
最適化された JSON 解析を使用してこれを達成する方法はありますか。現在、私のロジックは次の手順に従います。
- ノードをループしてオブジェクトを読み取る関数を使用して、オブジェクト全体を解析しています。
- すべてのオブジェクトで「blobChecker」関数を呼び出します。
- ブロブが含まれている場合、ノードに null を割り当てます。
- 「blobChecker」を呼び出す元の関数で null ノードをスキップする
JSON を解析する元の関数:
parseJsonNode(JsonNode node){
blobNodeChecker(node);
if(node!=null)
//The funtionality
}
blobNodeChecker 関数:
blobNodeChecker(JsonNode node) {
Boolean isBlob = false;
String blobNode = null;
Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
while (fields.hasNext()) {
Map.Entry<String, JsonNode> next = fields.next();
String key = next.getKey();
String val = next.getValue().toString().toLowerCase();
if (key.equals("@type")) {
if (val.contains("blob")) {
isBlob = true;
break;
}
}
}
if (isBlob) {
node = null;
}
return node;
}