lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Noble Paul നോബിള്‍ नोब्ळ् <noble.p...@corp.aol.com>
Subject Re: Type converters for DocumentObjectBinder
Date Fri, 13 Nov 2009 09:18:21 GMT
you must have  a corresponding getter which returns String.
public String getValidFrom() {
       String s = null;//convert calendar to string
       return s;
}

On Fri, Nov 13, 2009 at 2:01 PM, paulhyo <steph@ouestil.ch> wrote:
>
> Hi Paul,
>
> it's working for Query, but not for Updating (Add Bean). The getter method
> is returning a Calendar (GregorianCalendar instance)
>
> On the indexer side, a toString() or something equivalent is done and an
> error is thrown
>
> Caused by: java.text.ParseException: Unparseable date:
> "java.util.GregorianCalendar:java.util.GregorianCalendar[time=1258100168327,areFieldsSet=
> rue,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=3600000,useDaylight=true,tran
> itions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMo
> th=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]
> ,firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2009,MONTH=10,WEEK_OF_YEAR=46,WEEK_OF_MONTH=2,DAY_OF_MONTH=13,DAY_OF_YEAR=317,DAY_OF_WEEK=
> ,DAY_OF_WEEK_IN_MONTH=2,AM_PM=0,HOUR=9,HOUR_OF_DAY=9,MINUTE=16,SECOND=8,MILLISECOND=327,ZONE_OFFSET=3600000,DST_OFFSET=0]"
>
>
> public Calendar getValidFrom() {
>        return validFrom;
> }
>
> public void setValidFrom(Calendar validFrom) {
>        this.validFrom = validFrom;
> }
>
> @Field
> public void setValidFrom(String validFrom) {
>        Calendar cal = Calendar.getInstance();
>        try {
>                cal.setTime(dateFormat.parse(validFrom));
>        } catch (ParseException e) {
>                e.printStackTrace();
>        }
>        this.validFrom = cal;
> }
>
>
>
>
>
>
> Noble Paul നോബിള്‍  नोब्ळ्-2 wrote:
>>
>> create a setter method for the field which take s a Stringand apply
>> the annotation there
>>
>> example
>>
>>
>> private Calendar validFrom;
>>
>> @Field
>> public void setvalidFrom(String s){
>>     //convert to Calendar object and set the field
>> }
>>
>>
>> On Fri, Nov 13, 2009 at 12:24 PM, paulhyo <steph@ouestil.ch> wrote:
>>>
>>> Hi,
>>>
>>> I would like to know if there is a way to add type converters when using
>>> getBeans. I need convertion when Updating (Calendar -> String) and when
>>> Searching (String -> Calendar)
>>>
>>>
>>> The Bean class defines :
>>> @Field
>>> private Calendar validFrom;
>>>
>>> but the recieved type within Query Response is a String (2009-11-13)...
>>>
>>> Actually I get this error :
>>>
>>> java.lang.RuntimeException: Exception while setting value : 2009-09-16 on
>>> private java.util.Calendar
>>> ch.mycompany.access.solr.impl.SoNatPersonImpl.validFrom
>>>        at
>>> org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.set(DocumentObjectBinder.java:360)
>>>        at
>>> org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.inject(DocumentObjectBinder.java:342)
>>>        at
>>> org.apache.solr.client.solrj.beans.DocumentObjectBinder.getBeans(DocumentObjectBinder.java:55)
>>>        at
>>> org.apache.solr.client.solrj.response.QueryResponse.getBeans(QueryResponse.java:324)
>>>        at
>>> ch.mycompany.access.solr.impl.result.NatPersonPartnerResultBuilder.buildBeanListResult(NatPersonPartnerResultBuilder.java:38)
>>>        at
>>> ch.mycompany.access.solr.impl.SoQueryManagerImpl.searchNatPersons(SoQueryManagerImpl.java:41)
>>>        at
>>> ch.mycompany.access.solr.impl.SolrQueryManagerTest.testQueryFamilyNameRigg(SolrQueryManagerTest.java:36)
>>>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>        at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>        at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>        at java.lang.reflect.Method.invoke(Method.java:597)
>>>        at junit.framework.TestCase.runTest(TestCase.java:164)
>>>        at junit.framework.TestCase.runBare(TestCase.java:130)
>>>        at junit.framework.TestResult$1.protect(TestResult.java:106)
>>>        at junit.framework.TestResult.runProtected(TestResult.java:124)
>>>        at junit.framework.TestResult.run(TestResult.java:109)
>>>        at junit.framework.TestCase.run(TestCase.java:120)
>>>        at junit.framework.TestSuite.runTest(TestSuite.java:230)
>>>        at junit.framework.TestSuite.run(TestSuite.java:225)
>>>        at
>>> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
>>>        at
>>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>>>        at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>>>        at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>>>        at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>>>        at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>>> Caused by: java.lang.IllegalArgumentException: Can not set
>>> java.util.Calendar field
>>> ch.mycompany.access.solr.impl.SoNatPersonImpl.validFrom to
>>> java.lang.String
>>>        at
>>> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
>>>        at
>>> sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
>>>        at
>>> sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
>>>        at java.lang.reflect.Field.set(Field.java:657)
>>>        at
>>> org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.set(DocumentObjectBinder.java:354)
>>>        ... 24 more
>>>
>>> Thank you in advance
>>>
>>> Paulhyo
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Type-converters-for-DocumentObjectBinder-tp26332174p26332174.html
>>> Sent from the Solr - User mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> -----------------------------------------------------
>> Noble Paul | Principal Engineer| AOL | http://aol.com
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Type-converters-for-DocumentObjectBinder-tp26332174p26333041.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
>



-- 
-----------------------------------------------------
Noble Paul | Principal Engineer| AOL | http://aol.com

Mime
View raw message