2017-07-28 13 views
0

我的目标是能够生成csv文件。现在只是试图返回JSON列表的ID。集成响应无法映射项目数组

我挣扎映射的响应,所以我的JSON是:

{ 
"items": [ 
     { 
      "id": "2017-07-02_n_Eleana Qorgyle", 
      "groupId": "n_2017-07"} 
] 
} 

和我的模型是

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "title": "Log", 
    "type": "object", 
    "properties": { 
    "items": { 
     "type": "array", 
     "items": { 
     "type": "object", 
     "properties": { 
      "id": { "type": "string" } 
     } 
     } 
    } 
    } 
} 

我Velocity模板是...

#set($inputRoot = $input.path('$')) 
{ 
    "items" : [ 
##TODO: Update this foreach loop to reference array from input json 
#foreach($elem in $inputRoot.items) 
{ 
    "id" : "foo" 
    } 
#if($foreach.hasNext),#end 
#end 
] 
} 

但是,我得到这个输出:

{ 
    "items": [] 
} 

我错过了什么吗? $ inputRoot.body输出一切,但迭代是一个问题。

+0

我试着用你在这里发布的设置。我能够获得'''{“items”:[{“id”:“foo”}]}'''。我想你可能会忘记部署你的API。 –

+0

是的,API部署,只需将indexRoot.items工作正常。迭代通过它是问题。 –

回答

0

我想这是你正在尝试做的:

#set($inputRoot = $input.path('$')) { 
     "items" : [ 
     #foreach($elem in $inputRoot.items){ 
     "id" : "$elem.get('id')" 
     } 
     #if($foreach.hasNext),#end 
     #end 
     ] 
    } 

谢谢!