Days ago I had to consume a Rest API and save the data into my MongoDB gateway data store. I used groovyx.net.http.RESTClient simply because it’s simple to use.
My problem was that inside the JSON response there were few BigDecimal attributes (converted automatically using HttpResponseDecorator) and BigDecimal is not supported in MongoDB (check here / and here).
My first approach was hardcode those attributes and save them as Double – but then I discovered the structure could be completely different based on business rules (each request acts differently).
So I decided to create a Closure which goes “recursively” into the Map searching for BigDecimal attributes. Just mentioned “recursively” ’cause the idea is to use the same recursive approach (I don’t know the tree structure) but avoiding StackOverflow using trampoline, considering the JSON response is quite big.
Here is my piece of code:
I have not found any other solution so far, let me know whether you have any trick one 😉