我開始爲現有的JSF-webapp(使用RESTEasy,使用Jettison提供程序)實現REST層。由於Java REST圖層的教程是非常基礎的(簡單對象),所以我正面臨着現有的JPA實體關係如何輕鬆地暴露給客戶端/從客戶端消耗的問題。一個簡單的「/用戶」REST方法已經成功地爲我提供了下面的輸出,這是一個好的開始。但我的主要問題是 - 如何處理這種結構。通過REST使用這樣的結構是否很常見?如何合併POST/PUT上的JPA實體結構RESTful webapp
- 我不想公開所有細節或整個實體樹,這是因爲無關緊要,節省了流量或安全問題。使用@XmlTransient對@Procudes工作正常,但將@ POST/@ PUT合併這些實體,所有@XmlTransient屬性合併爲NULL。什麼是正確的做法?
- 由於@XMLTransient是一個全局和永久的設置 - 什麼是正確的方法來動態地決定我想要公開的實體樹的深度?
感謝
用戶的實體的示例JSON:
{
"user": {
"id": ..,
"uuid": "1521ccad69ba4579bbe49e75181fefc1",
"image": "",
"contact": {
"id": ..,
"uuid": "8eb429dcca994834ae5c8cf07cba62a2",
"cellphone": "",
"city": "",
"country": "",
"email": "[email protected]",
"fax": "",
"phone": 555,
...
},
"name": "...",
"account": {
"id": ...,
"uuid": "80b331f9e6644449bb3600b0e5145253",
"confirmed": true,
"profile": {
"id": ...,
"uuid": "e172bdcafe2645d7975852ca5685c98c",
"locale": "en",
"notifyMessage": false,
"notifyNews": true,
"notifyTask": true,
"timeZone": "Europe/Berlin"
},
"roleProfiles": {
"id": ..,
"uuid": "f1713758f3f2416faed3e68350f2d759",
"active": true,
"assemblies": [
{
"id": ..,
"uuid": "13d72449833a4eb0b5b4f62c729ee44f",
"image": "",
"commercialRegisters": [
123,
456
],
"contact": {
"id": ...,
"uuid": "bef3802297344e3c8c3619b6c91c345a",
"city": "",
"country": "",
...
},
"thumbnail": ""
},
{
...
}
],
},
"userName": "..."
},
"displayName": "...",
"firstName": "Foo",
"lastName": "Bar",
"salutation": "",
"title": ""
}
}