2016-07-14 57 views
0

我正在使用Watson對話。我得到當試圖執行一個ServiceCall,在ResponseUtils的90線的異常(在的getObject):Watson對話:無法執行ServiceCall

final T model = GsonSingleton.getGsonWithoutPrettyPrinting().fromJson(reader, type); 

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 647 path $.output.text 

我探索響應和我看到: 響應{協議= HTTP/1.1,代碼= 200,消息= OK,URL = https://gateway.watsonplatform.net/conversation-experimental/api/v1/workspaces/200afa7d-c71f-472a-ab6e-5bf162f6e319/message?version=2016-05-19}

這是我的代碼:

import com.ibm.watson.developer_cloud.conversation.v1_experimental.ConversationService; 
import com.ibm.watson.developer_cloud.conversation.v1_experimental.model.Message; 
import com.ibm.watson.developer_cloud.conversation.v1_experimental.model.NewMessageOptions; 
import com.ibm.watson.developer_cloud.conversation.v1_experimental.model.NewMessageOptions.Builder; 
import com.ibm.watson.developer_cloud.http.ServiceCall; 

public class TestConversation { 
    public static void main(String[] args) throws Exception{ 

     ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_05_19); 
     service.setEndPoint("https://gateway.watsonplatform.net/conversation-experimental/api"); 
     service.setUsernameAndPassword("xxxxxxxx", "xxxxxx"); 

     Builder builder = new NewMessageOptions.Builder().workspaceId("xxxxxxxxxxxx"); 
     NewMessageOptions newMessageOptions = builder.inputText("hi").build(); 

     ServiceCall<Message> serviceCall = service.message(newMessageOptions); 
     Message answer = serviceCall.execute(); 
    } 
} 

回答

0

解決。我改變了對沃森的其他SDK: https://github.com/watson-developer-cloud/java-sdk/tree/7db5d534250200625691a186c8b2aa4f98bb6a20

所以,我用這個代碼,並能正常工作:

ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_05_19); 
service.setUsernameAndPassword("xxxxxxxxx", "xxxxxxx"); 
service.setEndPoint("https://gateway.watsonplatform.net/conversation-experimental/api"); 

MessageRequest newMessage = new MessageRequest.Builder().inputText("Hola").build(); 
MessageResponse response = service.message("xxxxxxxx", newMessage).execute(); 
System.out.println(response.getText());