2013-04-29 46 views
0

我創建了一個休息服務器。使用POST方法,我發送了以下數據:Grails使用urlmapper休息,如何刪除休息請求的類名

{"class":"abc.User","email":"[email protected]"} 

,以確保它正常工作,我用捲曲:當我創建其餘客戶端發送的數據出現

curl --request POST --data '{"class":"abc.User","email":"[email protected]"}' --header "Content-Type: application/json" http://localhost:8081/abc/api/add 

的問題。我使用rest-client-builder插件。

我的客戶端代碼:

def resp = rest.post("http://localhost:8082/abc/api/add"){ 

contentType "application/json" 

json { 
    class = "dsi.ewallet.prepaidserver.Kartu" 
    email = "[email protected]" 
} 

}

我得到了錯誤: 「意外的標記」 如果我刪除了 '類',它解決問題。但是我的其他服務器需要傳遞類名。

有沒有辦法解決它?或者如何刪除需要傳遞類名稱的其餘服務器?謝謝。

+1

我猜班級是保留的工作,你可以稱它爲「className」或「clazz」? – lucke84 2013-04-29 09:57:23

回答

0

工作,我決定使用JSONBuilder()

def builder = new JSONBuilder() 
String result = builder.build() { 
    setProperty("abc", abcValue) 
    setProperty("def", defValue) 
} 
return result 

當我需要構建更復雜的結構,我只創建一個包含屬性Groovy類。然後將數據填入該類,並與JSONBuilder()一起使用。

0

我認爲問題是java中的類是保留字,因爲您可以使用Class.classthis.getClass(),所以它在解析時會出現問題,所以我認爲您必須更改此屬性的名稱。

它的捲曲度,因爲它不是用java