I'm using Watson Conversation. I get an exception when trying to execute a ServiceCall, at line 90 of ResponseUtils (in getObject):
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
I explore the response and I see this: Response{protocol=http/1.1, code=200, message=OK, url= https://gateway.watsonplatform.net/conversation-experimental/api/v1/workspaces/200afa7d-c71f-472a-ab6e-5bf162f6e319/message?version=2016-05-19 }
This is my code:
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();
}
}
Solved. I changed to other sdk of Watson: https://github.com/watson-developer-cloud/java-sdk/tree/7db5d534250200625691a186c8b2aa4f98bb6a20
So, I use this code and it works fine:
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());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.