Hardik Patel Hardik Patel - 5 months ago 30
JSON Question

Grails LazyMap to POJO Conversion failed due to Date value

I am using Grails 2.4 and jersey request builder plug-in.

I am getting below error on

def resRequestList = RESPONSE FROM REST REQUEST
ResourceTest item1 = resRequestList.get(0)


error is

Cannot cast object '{createdBy=2576, endDate=10-Jun-2016, id=14}'
with class 'groovy.json.internal.LazyMap' to class 'com.modal.resource.ResourceTest'

due to: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '10-Jun-2016' with class 'java.lang.String' to class 'java.util.Date'


It looks like conversion failed from Sting to Date.

I needs solution to map it automatically to POJO without string to date conversation error.

There should be anything which do preprocessing before casting.

Please Help.

Answer

Finally I find alternate solution which is best fit to me.

I have used reflection to get original List of Object using GenericType.

My Code is as below

def resRequestList = clientResponse.getEntity(new GenericType<ArrayList<ResourceTest>>(){});