mboudreau / Alternator

A mock DynamoDB that runs locally for testing purposes - DEPRECATED, PLEASE USE DYNAMODB LOCAL: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html
Apache License 2.0
78 stars 39 forks source link

JSONException when using Set of Strings #28

Closed andresilva closed 12 years ago

andresilva commented 12 years ago

Hi,

I'm getting the following error:

com.amazonaws.AmazonClientException: Unable to unmarshall error response (A JSONObject text must begin with '{' at 1 [character 2 line 1]) at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:550) at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:289) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:170) at com.michelboudreau.alternator.AlternatorDBClient.invoke(AlternatorDBClient.java:263) at com.michelboudreau.alternator.AlternatorDBClient.getItem(AlternatorDBClient.java:212) (…) Caused by: com.amazonaws.util.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] at com.amazonaws.util.json.JSONTokener.syntaxError(JSONTokener.java:422) at com.amazonaws.util.json.JSONObject.(JSONObject.java:183) at com.amazonaws.util.json.JSONObject.(JSONObject.java:310) at com.amazonaws.http.JsonErrorResponseHandler.handle(JsonErrorResponseHandler.java:42) at com.amazonaws.http.JsonErrorResponseHandler.handle(JsonErrorResponseHandler.java:29) at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:531) ... 20 more

The error happens when I use a set of strings as a value (i.e. withSS()). The same code works perfectly using the original dynamo client.

mboudreau commented 12 years ago

Thanks for posting. Can I ask for you to show the code that you were using? I want to be able to reproduce this issue and fix it where possible.

Cheers.

andresilva commented 12 years ago

Hey,

I just cloned the repo to assembly the jar and noticed that the tests fail on my system (with the same error I'm reporting).

Results :

Failed tests: queryWithHashKey(com.michelboudreau.test.AlternatorQueryTest) scanWithScanFilterGTTest(com.michelboudreau.test.AlternatorScanTest) scanWithScanFilterLTTest(com.michelboudreau.test.AlternatorScanTest) scanPaginationTest(com.michelboudreau.test.AlternatorScanTest)

Tests in error: scanWithScanFilterLETest(com.michelboudreau.test.AlternatorScanTest): Unable to unmarshall error response (A JSONObject text must begin with '{' at 1 [character 2 line 1]) scanWithScanFilterINTest(com.michelboudreau.test.AlternatorScanTest) scanWithScanFilterBETWEENTest(com.michelboudreau.test.AlternatorScanTest)

Tests run: 48, Failures: 4, Errors: 3, Skipped: 0

My code is rather complex but if you want to I can try and create a simple test case to reproduce this.

mboudreau commented 12 years ago

Yes, the tests are still a little wonky. We need to fix that.

But yeah, if you can create a simple test case to reproduce it, it would be hugely helpful. Thanks.

andresilva commented 12 years ago

Hi,

I've tracked down the source of this bug on my code and it has nothing to do with using sets of strings (that was just a coincidence, sorry). The issue seems to arise when I try to get attributes that don't exist. I've created a gist with a simple test case that triggers the issue (https://gist.github.com/2967278). If you comment line 56 it works.

Maybe you can check if the attribute exists before trying to fetch it from the table? Maybe here: https://github.com/mboudreau/Alternator/blob/master/src/main/java/com/michelboudreau/alternator/AlternatorDBHandler.java#L317 ?

Beware that I'm not sure this is the correct behavior of the original dynamo client, I'm assuming it is since all my tests pass when using it.

Cheers!

mboudreau commented 12 years ago

That's awesome feedback and that's so much for the code. That will make it that much easier to fix :)

I'll try to get it working tomorrow. Cheers.