On Apr 28, 2009, at 6:21 PM, Tatu Saloranta wrote:
> On Tue, Apr 28, 2009 at 8:21 AM, Paul Sandoz <Paul.Sandoz_at_sun.com>  
> wrote:
>>
>> On Apr 28, 2009, at 8:38 AM, Tatu Saloranta wrote:
>>
>>> I just pushed out second 1.0 release candidate for Jackson json
>>> processor (see http://jackson.codehaus.org/Download); and there are
>>
>> Great! Perhaps we should can a sample to Jersey that utilizes this  
>> feature?
>
> That might be useful? Although for simplest cases, there's really no
> change to the usual pattern of getting content in and/or returning
> content as MediaType.APPLICATION_JSON.
> But it might be useful to show-case some configuration -- for example,
> how to enable indentation (pretty-print) for writing.
>
> That's something I do for testing purposes, see below (I suspect it'd
> be simpler to just register ObjectMapper instance... but this works
> too)
>
> However there is still the question of whether and how to integrate
> this with the json-content configuration framework of jersey-json.
>
Yes. Currently things should work with Jackson/JAX-RS/JSON for non- 
JAXB objects or when jackson/JAX-RS/JSON is in the class path before  
jersey-json.
If we integrate the direct Jackson/JAX-RS/JSON into jersey-json we  
would need some option to disable/enable one or the other. But it  
could be really tricky if an application wants to support both. The  
only solution i can think of is:
      define a Jackson/JSON POJO annotation for use with JAXB, if  
annotated with that then the Jersey JAXB readers/writers
      will not be utilized for the type. Or say the inverse: an  
annotation to state that JAXB should not be used for anything but
      XML.
Paul.
> -+ Tatu +-
>
> --- ObjectMapper config for Jackson JAX-RS+json provider ---
>
> @Produces
> public final class ObjectMapperConfig
>    implements ContextResolver<ObjectMapper>
> {
>   final ObjectMapper _mapper;
>
>    private ObjectMapperConfig()
>    {
>        _mapper = new ObjectMapper();
>        // Enable pretty-printing for testing;
>        _mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT,  
> true);
>    }
>
>    public ObjectMapper getContext(Class<?> type) {
>        if (type == ObjectMapper.class) { // should always be true
>            return _mapper;
>        }
>        return null;
>    }
> }
>
> public final class RestApplication
>    extends Application
> {
>    // ...
>    @Override
>    public Set<Object> getSingletons()
>    {
>        HashSet<Object> singletons = new HashSet<Object>();
>        singletons.add(new ObjectMapperConfig());
>        // ... or could just add plain ObjectMapper instance?
>    }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>