On Wed, Mar 14, 2012 at 11:22 PM, Richard Berger
<[email protected]>wrote:
> Is it possible that when seeing the following code: (from my test case)
>
> Comment comment = new Comment("Hi there from Java", new Date());
> Representation representation4 = commentsResource.postJava(comment);
>
> the fact that I am using Jackson somehow instructs the system to convert my
> Java object (comment) into Json and since it is now in Json, the postJson
> method is called.
>
As I said, the conneg and conversion dance is delicate. I think it's a
server-side problem, not with Jackson itself, but due to the Jackson
extension jar (org.restlet.ext.jackson.jar), which registers
JacksonConverter with the Restlet Engine.
Because the order that converters are registered with the Engine is
dependent on classloader behavior and thus not predictable in general, the
decision of which converter to use has been designed to be
order-independent, using complicated scoring and client preference
adjustment logic that I can never keep in my head for more than a few
minutes at a time, and then only after sitting in a lotus position for an
hour. :-)
So ... sorry, but this is one that the Restlet guys will have to tackle for
you.
But my advice is to drop the @Post("java") option entirely. Jackson
serialization is very fast and reasonably compact, it works with objects
that don't implement java.io.Serializable, and you can exchange JSON
representations with non-Java clients. If you really want a compact binary
format that can be processed quickly, one line of code can instruct Jackson
to work in terms of the binary Smile format.
There is a learning curve to Jackson, but it has been well worth it for me:
- I've written generic implementations of equals and hashCode for my
Java representation types so I can use them in collections and maps, by
comparing and hashing serialized forms. (I can selectively override them if
I need to for speed, but I haven't needed to yet.)
- I've written generic copy and update methods similarly. (No clones
here!)
- I've implemented serializability for a data-grid library I use
(Hazelcast) in terms of Smile.
--tim
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2935973