Hi Keith,
As you said I set it after mapping file. However, this did not work
for my project. Then i created a small project and tried a simple
serialization with a POJO and i could see that both mapping and
fieldhandler feature is successfully applied by castor.
In this case , the only difference between successful and failed
project is that in my project i generate objects using source
generator. After I had a look at castor source code while debugging,
I concluded with that castor always uses XMLFieldHandler for element
manipulation which is defined inside Descriptor classes. So this means
that my GeneraliazedFieldHandler never used by castor.
My current marshaller setting:
Mapping mapping = new Mapping();
InputSource source=new
InputSource(Thread.currentThread().getContextClassLoader().getResourceAsStream("conf/mapping.xml"));
mapping.loadMapping(source);
FieldHandlerFactory factory=new BooleanFHFactory();
ClassDescriptorResolverImpl cdr = new ClassDescriptorResolverImpl();
cdr.getIntrospector().addFieldHandlerFactory(factory);
marshaller.setResolver(cdr);
marshaller.setMapping(mapping);
does it make sense a bit? do i need to define something in the binding file?
sorry for time consuming.
mesut
On 10/12/05, Keith Visco <[EMAIL PROTECTED]> wrote:
>
> Hi Mesut,
>
> Try setting the mapping file *after* you set the
> ClassDescriptorResolver. You will note the following in the Javadoc for
> Marshaller#setResolver:
>
> <B>Note:</B> This method will nullify any Mapping
> currently being used by this Marshaller
>
> http://castor.codehaus.org/javadoc/org/exolab/castor/xml/Marshaller.html#setResolver(org.exolab.castor.xml.ClassDescriptorResolver)
>
>
> --Keith
>
>
> Mesut Celik wrote:
> > Hi Keith,
> > I applied your workaround and it did work with a strange behaviour.
> >
> > FieldHandlerFactory factory=new BooleanFHFactory();
> > ClassDescriptorResolverImpl cdr = new ClassDescriptorResolverImpl();
> > cdr.getIntrospector().addFieldHandlerFactory(factory);
> > marshaller.setResolver(cdr);
> >
> > what is weird is when assigning this resolver implementation to
> > marshaller the mapping file which i use and assigned to marshaller at
> > the same time automatically became unused but i could serialize all
> > boolean fields as 0/1 pair.
> > Since i need both mapping definitions and this fieldhandler mechanism,
> > current behaviour cannot help to solve my problem.
> >
> >
> > what can be the cause of problem? I feel im approaching to finish point...:)
> >
> >
> > thanks in advance
> > mesut
> >
> >
> > On 10/10/05, Mesut Celik <[EMAIL PROTECTED]> wrote:
> >
> >>On 10/8/05, Keith Visco <[EMAIL PROTECTED]> wrote:
> >>
> >>>Mesut Celik wrote:
> >>>
> >>>>hi keith,
> >>>>
> >>>>what about the mapping.xml file? Actually I had written an
> >>>>GeneralizedFieldHandler without handlerFactory and then assigned the
> >>>>handler to some fields in the mapping file before your mail and it did
> >>>>not work.
> >>>
> >>>
> >>>How did you specify your handler and what does your handler
> >>>implementation look like? Did you take a look at the online
> >>>documentation for writing custom handlers?
> >>
> >>yes i did. I followed online documentation but not heard about
> >>FieldhandlerFactory on the web site. could you give me an example how
> >>to create this factory class for boolean types.
> >>
> >>
> >>>>my question is you did not mention about mapping file in
> >>>>your mail. dont I have to use mapping file? and what should i do if i
> >>>>need only some fields to be handled and not the others?
> >>>
> >>>Yes you can use a mapping file, which is the normal way to specify
> >>>custom handlers, but if you wanted to handle all Boolean values in your
> >>>application the same way then it's easier to write a
> >>>FieldHandlerFactory. If you only want some values to be handled a
> >>>certain way, then a mapping file is the better approach.
> >>>
> >>
> >>again, i wanna handle all boolean values but unable to implement
> >>FieldHandlerFactory. can you give me more detailed information about
> >>the methads that need to be implemented in the abstract
> >>FieldHandlerFactory.
> >>
> >>isSupportedType
> >>getSupportedTypes
> >>createFieldHandler
> >>
> >>spesific explanation for boolean type would be appriciated.
> >>mesut
> >>
> >>
> >>
> >>>--Keith
> >>>
> >>>
> >>>>thanks in advance,
> >>>>mesut
> >>>>
> >>>>On 10/8/05, Keith Visco <[EMAIL PROTECTED]> wrote:
> >>>>
> >>>>
> >>>>>Mesut,
> >>>>>
> >>>>>You can write a GeneralizedFieldHandler and a FieldHandlerFactory. The
> >>>>>FieldHandlerFactory will prevent you from having to specify your
> >>>>>GeneralizedFieldHandler on every field that is a boolean. You can set
> >>>>>the FieldHandlerFactory directly on the Introspector as such:
> >>>>>
> >>>>> Marshaller m = new Marshaller(writer);
> >>>>> ClassDescriptorResolverImpl cdr = new ClassDescriptorResolverImpl();
> >>>>> cdr.getIntrospector().addFieldHandlerFactory(factory);
> >>>>> m.setResolver(cdr);
> >>>>>
> >>>>>Hope that helps,
> >>>>>
> >>>>>--Keith
> >>>>>
> >>>>>Mesut Celik wrote:
> >>>>>
> >>>>>
> >>>>>>Hi all,
> >>>>>>
> >>>>>>I wanna serialize boolean values of my objects as 0/1. I think one
> >>>>>>possible way of doing so is writing Generalized Field handler.
> >>>>>>Is there any other approach? or what is the best solution for such an
> >>>>>>issue?
> >>>>>>
> >>>>>>regards,
> >>>>>>mesut
> >>>>>>
> >>>>>>-------------------------------------------------
> >>>>>>If you wish to unsubscribe from this list, please
> >>>>>>send an empty message to the following address:
> >>>>>>
> >>>>>>[EMAIL PROTECTED]
> >>>>>>-------------------------------------------------
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>>-------------------------------------------------
> >>>>>If you wish to unsubscribe from this list, please
> >>>>>send an empty message to the following address:
> >>>>>
> >>>>>[EMAIL PROTECTED]
> >>>>>-------------------------------------------------
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>>-------------------------------------------------
> >>>>If you wish to unsubscribe from this list, please
> >>>>send an empty message to the following address:
> >>>>
> >>>>[EMAIL PROTECTED]
> >>>>-------------------------------------------------
> >>>>
> >>>>
> >>>
> >>>
> >>>-------------------------------------------------
> >>>If you wish to unsubscribe from this list, please
> >>>send an empty message to the following address:
> >>>
> >>>[EMAIL PROTECTED]
> >>>-------------------------------------------------
> >>>
> >>>
> >>
> >
> > -------------------------------------------------
> > If you wish to unsubscribe from this list, please
> > send an empty message to the following address:
> >
> > [EMAIL PROTECTED]
> > -------------------------------------------------
> >
> >
>
>
> -------------------------------------------------
> If you wish to unsubscribe from this list, please
> send an empty message to the following address:
>
> [EMAIL PROTECTED]
> -------------------------------------------------
>
>
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------