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.
-+ 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?
}
}