Quantcast

Jackson Mix-in Annotations...

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Jackson Mix-in Annotations...

Arnaud Petiteville
Hi,
I use the org.restlet.ext.jackson extension. I need to add Mix-in Annotations to a class, but how can I get the ObjectMapper used by the Restlet engine to configure it?
Thanks...

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2714383
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jackson Mix-in Annotations...

Tim Peierls
See if this thread helps answer your question:


The key idea is to override createObjectMapper so you can do your own configuration.

--tim

On Sat, Mar 26, 2011 at 12:52 PM, Arnaud Petiteville <[hidden email]> wrote:
Hi,
I use the org.restlet.ext.jackson extension. I need to add Mix-in Annotations to a class, but how can I get the ObjectMapper used by the Restlet engine to configure it?
Thanks...

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2714383

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Re: Jackson Mix-in Annotations...

Arnaud Petiteville
Hi,
Thanks for your answer; it is exactly what I need.
But can you explain how you do that: "Then I removed theJacksonConverterService from the engine and replace it with my local extension."?
Bye...

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2714739
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Re: Jackson Mix-in Annotations...

Tim Peierls
Whoops, sorry for the late reply. Here's another (different) pointer to what I think answers your question:


--tim

On Mon, Mar 28, 2011 at 8:15 AM, Arnaud Petiteville <[hidden email]> wrote:
Hi,
Thanks for your answer; it is exactly what I need.
But can you explain how you do that: "Then I removed theJacksonConverterService from the engine and replace it with my local extension."?
Bye...

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2714739

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Re: Re: Jackson Mix-in Annotations...

Arnaud Petiteville
Hi,
Thanks again. After your first answer I Googled and found the message pointed by the link you joined; but I still have the same problem I do not know how to do this: "At startup, I remove the existing one from the Engine and then add my local version.".
I use Restlet over GAE, I have a class ServerApplication that extends Application, I override the createInboundRoot method, in this method I can call this.getConverterService() which returns a list of converters. Do you use this list to remove and after add your local extension?
Could you please send some code?
Bye...

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2716106
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Re: Re: Jackson Mix-in Annotations...

Tim Peierls
On Fri, Apr 1, 2011 at 12:20 PM, Arnaud Petiteville <[hidden email]> wrote:
Thanks again. After your first answer I Googled and found the message pointed by the link you joined; but I still have the same problem I do not know how to do this: "At startup, I remove the existing one from the Engine and then add my local version.".
I use Restlet over GAE, I have a class ServerApplication that extends Application, I override the createInboundRoot method, in this method I can call this.getConverterService() which returns a list of converters. Do you use this list to remove and after add your local extension?
Could you please send some code?

I use a utility method. Sample usage: 

    replaceConverter(JacksonConverter.class, myLocalJacksonConverter);

Here's the code for the utility method:

    /**
     * Registers a new converter with the Restlet engine, after removing
     * the first registered converter of the given class.
     */
    static void replaceConverter(
            Class<? extends ConverterHelper> converterClass,
            ConverterHelper newConverter) {

        ConverterHelper oldConverter = null;

        List<ConverterHelper> converters = Engine.getInstance().getRegisteredConverters();
        for (ConverterHelper converter : converters) {
            if (converter.getClass().equals(converterClass)) {
                converters.remove(converter);
                oldConverter = converter;
                break;
            }
        }

        converters.add(newConverter);

        if (oldConverter == null) {
            logger.debug("Added {} to Restlet Engine", newConverter.getClass());
        } else {
            logger.debug("Replaced {} with {} in Restlet Engine", oldConverter.getClass(), newConverter.getClass());
        }
    }

--tim
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Re: Re: Re: Jackson Mix-in Annotations...

Arnaud Petiteville
Hi,
Now this is clear for me and it works.
Thanks a lot.
Bye...

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2716852
Loading...