aws-sdk-java icon indicating copy to clipboard operation
aws-sdk-java copied to clipboard

Adding List support in Item.withJSON

Open madhurpyasi opened this issue 11 years ago • 5 comments

I'm getting following error while writing a new item in DynamoDB using DocumentAPI.

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token at [Source: [{"chargeId":"charge-1","containerChargeName":"charge-1","chargeType":"BASE","serviceProviderId":"UPS","buyerId":"AMAZON","contractType":"WAREHOUSE_TRANSFER","chargeAmount":66.67,"currencyCode":"USD"}]; line: 1, column: 1] at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164) at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:691) at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:685) at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:308) at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:26) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2993) Also one thing I've noticed is that Item.withJSON is transforming JSON to Map instead of List because of which I'm getting this error

Is there any way to store a JSON list in new Document API?

madhurpyasi avatar Jul 11 '15 07:07 madhurpyasi

You can do it today by JSON-parsing the String into a List yourself and passing it to Item.withList, but it'd definitely be nice to support this out of the box - either by adding an explicit withJsonArray or having withJson try to figure out whether the input is an array or object. We'll add this to our backlog, or we'd be happy to look at a pull request.

david-at-aws avatar Jul 13 '15 16:07 david-at-aws

Please review my PR for this issue: https://github.com/aws/aws-sdk-java/pull/688

harshith-ch avatar Apr 17 '16 00:04 harshith-ch

@david-at-aws Can you take a look at the PR above?

harshith-c avatar Apr 20 '16 15:04 harshith-c

@david-at-aws is no longer at aws, but the change looks reasonable to me.

fernomac avatar Apr 20 '16 16:04 fernomac

The PR is merged, closing this issue.

zhangzhx avatar Apr 21 '16 00:04 zhangzhx