Java中的JSON嵌套PII数据屏蔽 [英] JSON Nested PII data masking in Java

查看:71
本文介绍了Java中的JSON嵌套PII数据屏蔽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要屏蔽以下JSON数据:给定JSON:

I need to mask the following JSON data : given JSON:

{  
        "key1":"value1",  
        "key2":"value2",  
        "key3": {  
            "key4":"value3"  
        }   
} 

Maksed data :
{  
       "key1":"value1",  
       "key2":"value2",  
       "key3": {  
             "key4":"000000"  
       }   
} 

我们已经有一个问题 Java中的JSON PII数据屏蔽如果键是主要响应的一部分(例如key1,key2或key3),则whoes答案有效,但是我需要一些用于嵌套值的东西.(使用杰克逊)

we already have a question JSON PII data masking in Java whoes answer works if the key is part of the main response(for example key1 , key2 or key3) , but i need something for nested values. (using jackson)

如果我们有需要屏蔽的json属性名,但根据接收到的响应,它在JSON中的位置可能不同,该怎么办.如何掩盖这些值?示例:我只知道我需要屏蔽"key4"值.

What if we have the json property name's that we need to mask but its position can differ in JSON depending on the response received. How to mask such values? Example : I only know that I need to mask "key4" value.

推荐答案

您已经有了答案.Jackson将为每个嵌套属性创建一个 Map .您可以使用上一个问题的答案,而只需更改地图的过程

you already have the answer. Jackson will create a Map for every nested property. You can use the answer from previous question and just change the process of the map

// Process map
if (map.containsKey("key3")) {
    Map<String, Object> nestedMap = (Map<String, Object>)map.get("key3");
    if (nestedMap.containsKey("key4")) {
        nestedMap.put("key4","000000");
    }
}

这篇关于Java中的JSON嵌套PII数据屏蔽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆