-
Notifications
You must be signed in to change notification settings - Fork 528
TypedRelation service call in Alchemy Language Java SDK not returning entities #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I feel like this can be done with POJOs and without TypeAdapters. Is that something you have looked into @nastacio ? |
|
I have not used this Google library before (I know it is popular) , but I understand a plain-POJO The fundamental problem resides with the payload design itself, which is unnecessarily verbose Denilson Nastacio
|
|
@nastacio: I totally agree with your opinion about the payload design - it is complex! That cluttering of the Watson Java SDK is a definitely problem we're facing. Nevertheless, we used the approach with POJOs throughout the Java SDK and try to keep the amount of custom (de)serializers low. Although unintuitive at first, this is benefitial in this case because of multiple reasons:
An example of a commit that solved a similar problem is 8a13f41 |
|
@max-vogler: at some point one must decide what is the fundamental interface for developers: the server payload or the language binding. The design for the server payload goes from verbose (e.g. the "arguments/argument" wrappers) to whimsical ( the "part:first | second" elements inside the "argument" element) to inconsistent (the "argument" element only exists in XML, but not in JSON) , so I somehow assumed it would make sense to exorcise some of it in the language binding. I definitely understand the choice of POJOs as a design philosophy that makes the the API mappings more predictable for people familiar with the server payload API, so I mean no criticism towards that approach. That said, points #2 and #3 on maintainability/testing/etc were lost on me. The presumed savings in not writing the tedious test code for null pointers and multiple payload variants were the very cause of this bug. The GSON library glides over misalignments between payload and Java classes and will silently assign null pointers to attributes it cannot find in the payloads, so that you still need to test all of the mapping possibilities even if you did not rely on type adapters. If the idea is to stick to a literal mapping (thus eliminating the inherent obscurity of type adapters) AND to cut down on testing the payload mapping and variations to the nth degree, then those two purposes may be best served by creating an XSD schema from complete payloads (couple of clicks on a decent IDE) and then using the xjc compiler to automatically generate the POJOs. |
|
Hi, When this request will be merge to a new version of the API ? Thanks. |
Current coverage is 75.43% (diff: 62.72%)@@ master #370 diff @@
==========================================
Files 66 66
Lines 2328 2410 +82
Methods 0 0
Messages 0 0
Branches 412 424 +12
==========================================
+ Hits 1759 1818 +59
- Misses 306 321 +15
- Partials 263 271 +8
|
🐛
This is a proposed fix for
#367
It takes the "arguments/argument" indirection into account when deserializing the server payloads into TypedRelation Java objects. Without this fix, the "entities" are not deserialized correctly and TypedRelation.getEntities() always returns a null pointer.
I also changed the type of TypedRelation.entities from Entity to TypedEntity, which seemed the original intention of the design all along.