Skip to content

ClassCastException when trying to send PiwikRequest with EcommeceItem #13

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

Closed
jahudi opened this issue Mar 14, 2016 · 5 comments
Closed
Assignees
Labels

Comments

@jahudi
Copy link

jahudi commented Mar 14, 2016

Hi,

when trying to send a PiwikRequest that contains an EcommerceItem a ClassCastException is thrown by the org.glassfish.json.JsonGeneratorImpl.write method since EcommerceItem cannot be cast to javax.json.JsonArray. See stack trace below.

java.lang.ClassCastException: org.piwik.java.tracking.EcommerceItem cannot be cast to javax.json.JsonArray
    at org.glassfish.json.JsonGeneratorImpl.write(JsonGeneratorImpl.java:275)
    at org.glassfish.json.JsonWriterImpl.writeArray(JsonWriterImpl.java:102)
    at org.glassfish.json.JsonWriterImpl.write(JsonWriterImpl.java:141)
    at org.glassfish.json.JsonArrayBuilderImpl$JsonArrayImpl.toString(JsonArrayBuilderImpl.java:266)
    at org.piwik.java.tracking.PiwikJsonArray.toString(PiwikJsonArray.java:61)
    at org.piwik.java.tracking.PiwikRequest.getUrlEncodedQueryString(PiwikRequest.java:1469)
    at org.piwik.java.tracking.PiwikTracker.sendRequest(PiwikTracker.java:49)
    ...

Test code that creates the error:

PiwikRequest request = new PiwikRequest(3, new URL("http://test-app.com/"));
request.enableEcommerce();
request.setEcommerceId(UUID.randomUUID().toString());
request.setEcommerceRevenue(5.99);
EcommerceItem item = new EcommerceItem("cashbundle.l", "Cash Bundle L", "Consumable", 5.99, 1);
request.addEcommerceItem(item);
PiwikTracker tracker = new PiwikTracker("http://my-tracking-server.com/piwik.php");
HttpResponse response = tracker.sendRequest(request);

The piwik-java-tracker library and its dependencies are included using maven:

<dependency>
    <groupId>org.piwik.java.tracking</groupId>
    <artifactId>piwik-java-tracker</artifactId>
    <version>1.0.1</version>
</dependency>

Any advice?

@mattab
Copy link
Member

mattab commented Mar 14, 2016

Hi @jahudi

We are currently looking for a maintainer and developer to manage the Piwik JAVA Tracker SDK. In case you are interested to collaborate on this SDK please let us know! We would welcome your help and pull request to make the SDK better and high quality 👍

@bcsorba bcsorba self-assigned this Mar 15, 2016
@mattab
Copy link
Member

mattab commented Mar 15, 2016

@bcsorba Sorry I didn't meant to say we are looking for maintainer, since obviously you are maintaining the SDK already :-) I got confused with our iOS SDK where we would love to find new maintainers. Thank you for your work!

@bcsorba
Copy link
Collaborator

bcsorba commented Mar 15, 2016

@mattab Haha not a problem at all and don't worry about it! Easy mistake to make :)

@jahudi Thanks for pointing this out - I was able to implement what I think is a workaround, but this highlights a problem that I created by making EcommerceItem a subclass of JsonValue. By allowing setters on EcommerceItem, this seems to go against the specs for JsonArray as found on https://jsonp.java.net/. A true fix to this may have to come through deprecating this class or its setters and potentially moving towards a different url construction pattern in 2.0

@bcsorba
Copy link
Collaborator

bcsorba commented Mar 15, 2016

Released in v1.0.2

@jahudi
Copy link
Author

jahudi commented Mar 15, 2016

@bcsorba Glad to help. Thanks for the quick fix!

@bcsorba bcsorba added the bug label Jul 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants