Description
The following simple Tradeoff Analytics Java program (renamed for attachment)TradeoffAnalyticsExample.txt appears to be valid. But it elicits a JsonParseException:
Exception in thread "main" com.google.gson.JsonParseException: The JsonDeserializer com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@e6fb1de0 failed to deserialize json object [{"type":"numeric","key":"price","full_name":"Price","format":"number:2","goal":"min","is_objective":true},{"type":"numeric","key":"weight","full_name":"Weight","format":"number:0","goal":"min","is_objective":true},{"type":"categorical","key":"brand","full_name":"Brand","goal":"min","is_objective":true},{"type":"datetime","key":"rDate","full_name":"Release Date","format":"date: 'MMM dd, yyyy'","goal":"max","is_objective":false}] given the type java.util.List<com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.Column>
at com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:64)
at com.google.gson.JsonDeserializationVisitor.invokeCustomDeserializer(JsonDeserializationVisitor.java:92)
at com.google.gson.JsonObjectDeserializationVisitor.visitFieldUsingCustomHandler(JsonObjectDeserializationVisitor.java:117)
at com.google.gson.ReflectingFieldNavigator.visitFieldsReflectively(ReflectingFieldNavigator.java:63)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:120)
at com.google.gson.JsonDeserializationVisitor.visitChild(JsonDeserializationVisitor.java:110)
at com.google.gson.JsonDeserializationVisitor.visitChildAsObject(JsonDeserializationVisitor.java:99)
at com.google.gson.JsonObjectDeserializationVisitor.visitObjectField(JsonObjectDeserializationVisitor.java:63)
at com.google.gson.ReflectingFieldNavigator.visitFieldsReflectively(ReflectingFieldNavigator.java:69)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:120)
at com.google.gson.JsonDeserializationContextDefault.fromJsonObject(JsonDeserializationContextDefault.java:76)
at com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:54)
at com.google.gson.Gson.fromJson(Gson.java:551)
at com.google.gson.Gson.fromJson(Gson.java:498)
at com.ibm.watson.developer_cloud.util.ResponseUtils.getObject(ResponseUtils.java:105)
at com.ibm.watson.developer_cloud.service.WatsonService.executeRequest(WatsonService.java:184)
at com.ibm.watson.developer_cloud.tradeoff_analytics.v1.TradeoffAnalytics.dilemmas(TradeoffAnalytics.java:96)
at com.ibm.watson.developer_cloud.tradeoff_analytics.v1.TradeoffAnalyticsExample.main(TradeoffAnalyticsExample.java:119)
Caused by: java.lang.RuntimeException: Unable to invoke no-args constructor for class com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.Column. Register an InstanceCreator with Gson for this type may fix this problem.
at com.google.gson.MappedObjectConstructor.constructWithAllocators(MappedObjectConstructor.java:68)
at com.google.gson.MappedObjectConstructor.construct(MappedObjectConstructor.java:52)
at com.google.gson.JsonObjectDeserializationVisitor.constructTarget(JsonObjectDeserializationVisitor.java:42)
at com.google.gson.JsonDeserializationVisitor.getTarget(JsonDeserializationVisitor.java:60)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:104)
at com.google.gson.JsonDeserializationContextDefault.fromJsonObject(JsonDeserializationContextDefault.java:76)
at com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:54)
at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTypeAdapters.java:663)
at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTypeAdapters.java:624)
at com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:51)
... 17 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at com.google.gson.UnsafeAllocator$1.newInstance(UnsafeAllocator.java:48)
at com.google.gson.MappedObjectConstructor.constructWithAllocators(MappedObjectConstructor.java:64)
... 26 more
Caused by: java.lang.InstantiationError: com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.Column
at sun.misc.Unsafe.allocateInstance(Native Method)
... 32 more
The JSON object that is failing appears to be valid. German's initial diagnosis was
The error is probably the service response. The TA team may have changed the response and that breaks the Java SDK because it can't transform the JSON into a POJO. The problem is on my side. I will probably switch the date column to be String instead of trying to parse it.
I also mentioned the following, probably gratuitous, points in email, which I include here just for the sake of completeness.:
German, I failed to mention this on yesterday's call, but the format field is really just a passthru to the widget. The service itself doesn't use or interpret the field at all; it just sends it as-is to the widget. The same is true for the full_name and description fields of columns and for the name, description_html, and app_data fields of options. So you can probably just ignore whatever is in these fields entirely as long as they're defined as valid JSON strings or, for app_data, as key/value pairs.
Testing with java-sdk-2.10.0-jar-with-dependencies.jar.