Groovy Unmarshalling Json to a specific Object

If you have a simple POJO (Plain Old Java Object) or POGO (Plain Old Groovy Object), you can use Groovy's default Map based constructor to convert the JSON string to an Object type. package com.example.groovy import groovy.json.JsonBuilder import groovy.json.JsonSlurper import groovy.transform.ToString /** * Created…

Store current date time in Mongo in ISO format

I wanted to store current date time (in UTC time zone) in ISO format in Mongo with Groovy as the language. It is pretty straightforward with joda time library. First the code and then some explaination. import org.joda.time.DateTime import org.joda.time.format.DateTimeFormatter import org.joda.…

Retry with Spring - I

Spring batch provides an excellent paradigm to retry an operation in case the operation might succeed eventually. It offers couple retry strategies: a. Retry a certain number of times. (Covered below) b. Retry after a certain amount of time. (Will be covered in future post) From their docs: To make…

Throw dynamic exceptions in Spock tests from where block

It's pretty straightforward due to Groovy awesomeness! Without any further ado: import spock.lang.Specification /** * Created by ravi on 11/14/14. */ class SpockDynamicExceptionTest extends Specification { def "test 1234"() { given: def a = 1 when: exception.newInstance([message]) then: thrown(RuntimeException) where: exception | message RuntimeException | 'You are awesome' IOException…