Happy Business Starts Here

Highlighted
Senior Tutor

Java SDK

Hello, I am working on a new Zuora integration project and looking at the Java SDKs provided they look to be abandoned and not maintained by Zuora (last update 2yrs ago). The quickstart project doesnt look to compile either and issues reported have not been addressed.

 

What is the recommended way to integrating with Zuora APIs in Java? 

 

Thanks

Tags (1)
10 REPLIES 10
Zuora Documentation

Re: Java SDK

Hi rahulaga,

 

There is an open source tool called swagger-codegen that you can use to generate code libraries for the Zuora API. I would suggest that you try using this tool.

 

I've just written a post about how to generate a Python library, but you should be able to generate Java in a very similar way. Please see here:

 

How to Generate a Code Library From the Zuora OpenAPI Spec

 

Hope this helps,

David

Tags (1)
Senior Tutor

Re: Java SDK

hi David, thanks for your response. Yes I have tired that. I actually posted a question on Stack overflow:

https://stackoverflow.com/questions/50108245/swagger-client-codegen-does-not-include-optional-method...

 

In summary I have 2 unresolved issues:

1. Optional methods are not created (that stack overflow question)

2. When I do a POST action/query it responds with a "records" arrays. In Swagger this is a zObejct. However that zObject is empty with no properties so it is unable to deserialize the reponse. I think the swagger yaml you publish needs to be updated.

 

 

Hope you have some insights.

Thanks

Zuora Documentation

Re: Java SDK

For #1, could you give a specific example of something that's not being created that you were expecting to be created? I'm not exactly sure what you are referring to, sorry.

 

For #2, We've been looking into this recently to see if there's any way we can change our Swagger spec to work around the issue. It will take some more time to investigate - will let you know if we find a solution.

 

Many thanks,

David

Senior Tutor

Re: Java SDK

Thanks David, sure here are some details for #1.

 

Create the client as (using v 2.3.1 codegen-cli):

 

java -jar swagger-codegen-cli.jar generate -i https://www.zuora.com/wp-content/themes/zuora/yaml/swagger.yaml -l java -o z-api --library resttemplate

 

Now looking in the generated classes if you look at say OAuthApi, there is only one method with the signature:

createToken(String clientId, String clientSecret, String grantType, String zuoraTrackId)

This makes zuoraTrackId a required param so I must provide it even though it is optional in the spec.

 

Not so bad in this case but when there are tens of optional fields and I'm forced to provide all of them then its practically not very usable. Maybe I am missing some configuration for codegen as I would expect optional fields in spec are not required.

Zuora Documentation

Re: Java SDK

Hi rahulaga, thanks for clarifying.

 

I see what you mean about all the parameters. I think you can set parameters to null if you don't want to use them. But still, that is quite inconvenient. This at least seems to be a known problem with swagger-codegen: https://stackoverflow.com/questions/43044439.

 

I've done some more investigation into the issue you're seeing with zObject. The problem here is that what we've called zObject in our Swagger spec does not have a fixed set of fields; the names and types of the fields that could be returned in the API response depend on the type of object that you're querying.

 

I don't believe that we can fully capture this behavior in Swagger, other than to specify that zObject has some unnamed fields of unknown type (this is done via an additionalProperties declaration is Swagger). In theory, that would cause the ZObject class in Java to extend HashMap, which would then enable you to access the particular fields of each ZObject instance.

 

Unfortunately, it looks like this functionality is currently missing from swagger-codegen. See here: https://github.com/swagger-api/swagger-codegen/issues/7586. In any case, we'll update our Swagger file to support this functionality from our side, so that we are prepared for when swagger-codegen supports it.

 

For now, my only suggestion is that you manually modify the ZObject class in ZObject.java and insert HashMap<String, Object> in the appropriate place. For comparision, take a look at how the CalloutMergeFields class extends HashMap<String, String>.

 

Please let me know if you have any success with this workaround.

Senior Tutor

Re: Java SDK

Thanks David. I would be hesitant to modify autogenerated code as then it would need to part of my source control and not built on the build machine.

It seems like using Swagger codegen is not really an option then and I just need to manually use a http client and create my own POJOs for serialization/deserialization. It just adds a lot of boilerplate overhead and maintenence effort. It would be nice if Zuora provided a supported SDK. 

Zuora Documentation

Re: Java SDK

Hi rahulaga,

 

I hear what you're saying - I can understand why you wouldn't want to modify the autogenerated code.

 

I've just done some further investigation on this and I found that it's possible to modify the Swagger spec so that swagger-codegen inserts HashMap<String, Object> in ZObject.java; no need to manually modify the autogenerated code.

 

However, the Swagger change would be a workaround that would misrepresent our API (and could easily cause issues elsewhere) so I'm reluctant to make that change in our offical Swagger spec. But you would of course be free to modify your copy of the Swagger spec, and the necessary modification is very suitable to be scripted.

 

Here's what your script would need to do:

 

  1. Load our Swagger spec using a YAML parser, so that you can manipulate the spec as a native object.
  2. Set definitions.zObject to this object:
    {
      "type": "object"
      "additionalProperties": {
        "type": "object"
      }
    }
    Note that I'm using JavaScript notation for this example.
  3. Output the modified spec in JSON format.
  4. Feed the JSON file to swagger-codegen.

Is this process something that you'd be able to include in your workflow?

Senior Tutor

Re: Java SDK

Thanks, I will take a look. Let me figure out all APIs we end up using and what we will need. The other issue of being forced to send nulls is also not something that I like. 

Zuora Documentation

Re: Java SDK

As of April 2019, we are providing a separate Swagger spec that includes the workaround described above. It is available at:

https://assets.zuora.com/zuora-documentation/swagger-codegen-workaround.yaml

 

Update 5 May, 2019: We plan to provide this separate Swagger spec until June 2019.

 

See this Community post for more information.