Hello Gary,
your proposed solution should work as expected, you might want to do
something like cache (Map<T, String>) for converted instances (or store
just one value, depends on your scenario).
you will need to take care of concurrency.. you can sync access to your
cache or make it thread local (latter should be easier and better solution).
Regards,
Pavel
On 1/5/11 12:17 AM, Gary Moore wrote:
> Right now, we're doing a lot of this in our MessageBodyWriter(s):
>
> @Override
> public long getSize(PropValue value, Class<?> type, Type type1,
> Annotation[] annotations, MediaType mediaType) {
> //TODO: Do this
> return -1L;
> }
>
> The problem is that we're doing some objects->byte conversions in the
> MessageBodyWriter.writeTo method. The docs for MessageBodyWriter say
> getSize is called before writeTo, so to respond properly to getSize,
> we have to do the objects->byte conversions twice, once to get the
> size and another time to actually write it out.
>
> What is the Jersey lifecycle of MessageBodyWriters? Is it safe to do
> the converting in the getSize method, then save the result for use in
> the writeTo method?
>
> Thanks,
> Gary
>