从嵌套的Json中提取参数

从嵌套的Json中提取参数,json,objectmapper,Json,Objectmapper,我有一个json字符串,如下所示: { \"request\": { \"requestId\": \"dd92f43ec593d2d8db94193b7509f5cd\", \"notificationType\": \"EntityAttribute\", \"notificationSource\": \"ODS\" }, \"entityattribute\": { \"entityId\": \"1

我有一个json字符串,如下所示:

{
    \"request\": {
        \"requestId\": \"dd92f43ec593d2d8db94193b7509f5cd\",
        \"notificationType\": \"EntityAttribute\",
        \"notificationSource\": \"ODS\"
    },
    \"entityattribute\": {
        \"entityId\": \"123\",
        \"attributeType\": \"DATE_OF_BIRTH\"
    }
}
我想将entityattribute反序列化到对象:

public class EntityAttributeNotification {
    private String attributeType;
    private String entityId;
}
一种方法是首先使用json路径(即entityattribute/entityId)提取entityId和attributeType,并创建对象EntityAttributeNotification

我想知道是否有一种方法可以直接反序列化entityattribute到EntityAttributeNotification。
我也尝试过JsonMixin注释,但这不适用于这里。

通过以下方法,您可以提取嵌套JSON的
参数和

const object1 ={
    "request": {
        "requestId": "dd92f43ec593d2d8db94193b7509f5cd",
        "notificationType": "EntityAttribute",
        "notificationSource": "ODS"
    },
   "entityattribute": {
        "entityId": "123",
        "attributeType": "DATE_OF_BIRTH"
    }
};
var keys = [];
for (let [key, value] of Object.entries(object1)) {
    if(typeof value == 'object'){
        keys.push(key);
        for (let [key1, value1] of Object.entries(value)) {
            keys.push(key1);
        }
    }
    else{
        keys.push(key);
    }

}
console.log(keys);

通过以下方法,您可以提取嵌套JSON的
参数

const object1 ={
    "request": {
        "requestId": "dd92f43ec593d2d8db94193b7509f5cd",
        "notificationType": "EntityAttribute",
        "notificationSource": "ODS"
    },
   "entityattribute": {
        "entityId": "123",
        "attributeType": "DATE_OF_BIRTH"
    }
};
var keys = [];
for (let [key, value] of Object.entries(object1)) {
    if(typeof value == 'object'){
        keys.push(key);
        for (let [key1, value1] of Object.entries(value)) {
            keys.push(key1);
        }
    }
    else{
        keys.push(key);
    }

}
console.log(keys);