2

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.

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
Hardik Patel
  • 937
  • 3
  • 14
  • 39

2 Answers2

2

You can add @BindingFormat('dd-MMM-yyyy') annotation to your date field in ResourceTest class. You can also use grails.databinding.dateFormats config option to set default, global binding format. See this answer for details: Binding a Grails date from params in a controller.

I would also recommend not to send month as Jun as this is locale specific and may not work dependning on your environment.

Community
  • 1
  • 1
practical programmer
  • 1,604
  • 10
  • 15
  • Hi droggo. Thanks for reply, My ResourceTest class is POJO not POGO. How do i add @BindingFormat('dd-MMM-yyyy') in POJO class. – Hardik Patel Jun 21 '16 at 06:43
2

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>>(){});
Hardik Patel
  • 937
  • 3
  • 14
  • 39