Search code examples
wcfjsondatetimeillegalargumentexceptionodata4j

OData4j exceptions - "Odd number of characters" and "bad valueString part of keyString"


EDIT:

The solution was to make a view that mirrored the table in question and converted the date to varchar and then convert it back to date with a matching collation

END OF EDIT

Can anyone tell me why OData4j reads datetime values fine from one of my WCF Data Service server but runs into an illegal argument exception (bad valueString as part of keyString) when reading exact same datetime type with same format from another WCF Data Service?

java.lang.IllegalArgumentException: bad valueString [datetime'2012-01-24T14%3A57%3A22.243'] as part of keyString

The other problem is that when I ask for a JSON response from the service from which OData4j had no problem reading datetime types I get another illegal argument exception and the error message is - Odd number of characters.

java.lang.IllegalArgumentException: org.odata4j.repack.org.apache.commons.codec.DecoderException: Odd number of characters.

Because WCF Data Services can't have multiple sources, I've made 2 projects with each it's own Entity Data Model source (from existing database). And like I mentioned above, I'm getting these annoying errors.

To conclude...

Example 1: bad valueString as part of keyString - when reading datetime. Also happens with FormatType.JSON.

ODataConsumer customerInfoServices = ODataConsumer
                                     .newBuilder("http://10.0.2.2:41664/CustomerInfoWCFDataServices.svc/")
                                     .setFormatType(FormatType.ATOM)
                                     .build();

customer = customerInfoServices
           .getEntities("Customers")
           .select("name, id")
           .filter("id eq " + 5)
           .execute()
           .firstOrNull();

Example 2: Odd number of characters. Only happends with FormatType.JSON and no problem reading datetime.

ODataConsumer businessServices = ODataConsumer
                                 .newBuilder("http://10.0.2.2:35932/BusinessWCFDataServices.svc/")
                                 .setFormatType(FormatType.JSON)
                                 .build();

Enumerable<?> ordrer = businessServices
                       .getEntities("Orders")
                       .filter("custId eq " + customer.getProperty("id").getValue())
                       .execute();

What I want is to receive JSON responses (ATOM is still too bloaded for android) and no problems reading datetime properties.


No body able to help me?

I've been wearing my fingers down trying to find a solution on Google, without any luck.

The collation on the database without datetime problems is "Danish_Norwegian_CI_AS" and on the database with reading errors is "SQL_Danish_Pref_CP1_CI_AS". I don't know if this has any meaning but I have a suspescion it has something to do with it.


Solution

  • The solution was to make a view that mirrored the table in question and converted the date to varchar and then convert it back to date with a matching collation. :-)