,
Versioned
{
/**
* This header is useful on Windows, trying to deal with potential XSS attacks.
*/
public final static String HEADER_CONTENT_TYPE_OPTIONS = "X-Content-Type-Options";
/**
* Since class javax.ws.rs.core.NoContentException
only exists in
* JAX-RS 2.0, but we need 1.1 compatibility, need to (unfortunately!) dynamically
* load class.
*/
protected final static String CLASS_NAME_NO_CONTENT_EXCEPTION = "javax.ws.rs.core.NoContentException";
protected final static String NO_CONTENT_MESSAGE = "No content (empty input stream)";
/**
* Looks like we need to worry about accidental
* data binding for types we shouldn't be handling. This is
* probably not a very good way to do it, but let's start by
* blacklisting things we are not to handle.
*
* (why ClassKey? since plain old Class has no hashCode() defined,
* lookups are painfully slow)
*/
protected final static HashSet DEFAULT_UNTOUCHABLES = new HashSet();
static {
// First, I/O things (direct matches)
DEFAULT_UNTOUCHABLES.add(new ClassKey(java.io.InputStream.class));
DEFAULT_UNTOUCHABLES.add(new ClassKey(java.io.Reader.class));
DEFAULT_UNTOUCHABLES.add(new ClassKey(java.io.OutputStream.class));
DEFAULT_UNTOUCHABLES.add(new ClassKey(java.io.Writer.class));
// then some primitive types
DEFAULT_UNTOUCHABLES.add(new ClassKey(char[].class));
/* 27-Apr-2012, tatu: Ugh. As per
* [https://github.com/FasterXML/jackson-jaxrs-json-provider/issues/12]
* better revert this back, to make them untouchable again.
*/
DEFAULT_UNTOUCHABLES.add(new ClassKey(String.class));
DEFAULT_UNTOUCHABLES.add(new ClassKey(byte[].class));
}
/**
* These are classes that we never use for reading
* (never try to deserialize instances of these types).
*/
public final static Class>[] DEFAULT_UNREADABLES = new Class>[] {
InputStream.class, Reader.class
};
/**
* These are classes that we never use for writing
* (never try to serialize instances of these types).
*/
public final static Class>[] DEFAULT_UNWRITABLES = new Class>[] {
InputStream.class, // as per [Issue#19]
OutputStream.class, Writer.class,
StreamingOutput.class, Response.class
};
protected final static int JAXRS_FEATURE_DEFAULTS = JaxRSFeature.collectDefaults();
/*
/**********************************************************
/* General configuration
/**********************************************************
*/
/**
* Helper object used for encapsulating configuration aspects
* of {@link ObjectMapper}
*/
protected final MAPPER_CONFIG _mapperConfig;
/**
* Map that contains overrides to default list of untouchable
* types: true
meaning that entry is untouchable,
* false
that is is not.
*/
protected HashMap _cfgCustomUntouchables;
/**
* Whether we want to actually check that Jackson has
* a serializer for given type. Since this should generally
* be the case (due to auto-discovery) and since the call
* to check availability can be bit expensive, defaults to false.
*/
protected boolean _cfgCheckCanSerialize = false;
/**
* Whether we want to actually check that Jackson has
* a deserializer for given type. Since this should generally
* be the case (due to auto-discovery) and since the call
* to check availability can be bit expensive, defaults to false.
*/
protected boolean _cfgCheckCanDeserialize = false;
/**
* Feature flags set.
*
* @since 2.3
*/
protected int _jaxRSFeatures;
/**
* View to use for reading if none defined for the end point.
*/
protected Class> _defaultReadView;
/**
* View to use for writing if none defined for the end point.
*/
protected Class> _defaultWriteView;
/*
/**********************************************************
/* Excluded types
/**********************************************************
*/
public final static HashSet _untouchables = DEFAULT_UNTOUCHABLES;
public final static Class>[] _unreadableClasses = DEFAULT_UNREADABLES;
public final static Class>[] _unwritableClasses = DEFAULT_UNWRITABLES;
/*
/**********************************************************
/* Bit of caching
/**********************************************************
*/
/**
* Cache for resolved endpoint configurations when reading JSON data
*/
protected final LRUMap _readers
= new LRUMap(16, 120);
/**
* Cache for resolved endpoint configurations when writing JSON data
*/
protected final LRUMap _writers
= new LRUMap(16, 120);
protected final AtomicReference _noContentExceptionRef
= new AtomicReference();
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected ProviderBase(MAPPER_CONFIG mconfig) {
_mapperConfig = mconfig;
_jaxRSFeatures = JAXRS_FEATURE_DEFAULTS;
}
/**
* Constructor that is only added to resolve
* issue #10; problems with combination of
* RESTeasy and CDI.
* Should NOT be used by any code explicitly; only exists
* for proxy support.
*/
@Deprecated // just to denote it should NOT be directly called; will NOT be removed
protected ProviderBase() {
_mapperConfig = null;
_jaxRSFeatures = JAXRS_FEATURE_DEFAULTS;
}
/*
/**********************************************************
/* Configuring
/**********************************************************
*/
/**
* Method for defining whether actual detection for existence of
* a deserializer for type should be done when {@link #isReadable}
* is called.
*/
public void checkCanDeserialize(boolean state) { _cfgCheckCanDeserialize = state; }
/**
* Method for defining whether actual detection for existence of
* a serializer for type should be done when {@link #isWriteable}
* is called.
*/
public void checkCanSerialize(boolean state) { _cfgCheckCanSerialize = state; }
/**
* Method for marking specified type as "untouchable", meaning that provider
* will not try to read or write values of this type (or its subtypes).
*
* @param type Type to consider untouchable; can be any kind of class,
* including abstract class or interface. No instance of this type
* (including subtypes, i.e. types assignable to this type) will
* be read or written by provider
*/
public void addUntouchable(Class> type)
{
if (_cfgCustomUntouchables == null) {
_cfgCustomUntouchables = new HashMap();
}
_cfgCustomUntouchables.put(new ClassKey(type), Boolean.TRUE);
}
/**
* Method for removing definition of specified type as untouchable:
* usually only
*
* @since 2.2
*/
public void removeUntouchable(Class> type)
{
if (_cfgCustomUntouchables == null) {
_cfgCustomUntouchables = new HashMap();
}
_cfgCustomUntouchables.put(new ClassKey(type), Boolean.FALSE);
}
/**
* Method for configuring which annotation sets to use (including none).
* Annotation sets are defined in order decreasing precedence; that is,
* first one has the priority over following ones.
*
* @param annotationsToUse Ordered list of annotation sets to use; if null,
* default
*/
public void setAnnotationsToUse(Annotations[] annotationsToUse) {
_mapperConfig.setAnnotationsToUse(annotationsToUse);
}
/**
* Method that can be used to directly define {@link ObjectMapper} to use
* for serialization and deserialization; if null, will use the standard
* provider discovery from context instead. Default setting is null.
*/
public void setMapper(MAPPER m) {
_mapperConfig.setMapper(m);
}
/**
* Method for specifying JSON View to use for reading content
* when end point does not have explicit View annotations.
*
* @since 2.3
*/
public THIS setDefaultReadView(Class> view) {
_defaultReadView = view;
return _this();
}
/**
* Method for specifying JSON View to use for reading content
* when end point does not have explicit View annotations.
*
* @since 2.3
*/
public THIS setDefaultWriteView(Class> view) {
_defaultWriteView = view;
return _this();
}
/**
* Method for specifying JSON View to use for reading and writing content
* when end point does not have explicit View annotations.
* Functionally equivalent to:
*
* setDefaultReadView(view);
* setDefaultWriteView(view);
*
*
* @since 2.3
*/
public THIS setDefaultView(Class> view) {
_defaultReadView = _defaultWriteView = view;
return _this();
}
// // // JaxRSFeature config
public THIS configure(JaxRSFeature feature, boolean state) {
_jaxRSFeatures |= feature.getMask();
return _this();
}
public THIS enable(JaxRSFeature feature) {
_jaxRSFeatures |= feature.getMask();
return _this();
}
public THIS enable(JaxRSFeature first, JaxRSFeature... f2) {
_jaxRSFeatures |= first.getMask();
for (JaxRSFeature f : f2) {
_jaxRSFeatures |= f.getMask();
}
return _this();
}
public THIS disable(JaxRSFeature feature) {
_jaxRSFeatures &= ~feature.getMask();
return _this();
}
public THIS disable(JaxRSFeature first, JaxRSFeature... f2) {
_jaxRSFeatures &= ~first.getMask();
for (JaxRSFeature f : f2) {
_jaxRSFeatures &= ~f.getMask();
}
return _this();
}
public boolean isEnabled(JaxRSFeature f) {
return (_jaxRSFeatures & f.getMask()) != 0;
}
// // // DeserializationFeature
public THIS configure(DeserializationFeature f, boolean state) {
_mapperConfig.configure(f, state);
return _this();
}
public THIS enable(DeserializationFeature f, boolean state) {
_mapperConfig.configure(f, true);
return _this();
}
public THIS disable(DeserializationFeature f, boolean state) {
_mapperConfig.configure(f, false);
return _this();
}
// // // SerializationFeature
public THIS configure(SerializationFeature f, boolean state) {
_mapperConfig.configure(f, state);
return _this();
}
public THIS enable(SerializationFeature f, boolean state) {
_mapperConfig.configure(f, true);
return _this();
}
public THIS disable(SerializationFeature f, boolean state) {
_mapperConfig.configure(f, false);
return _this();
}
// // // JsonParser/JsonGenerator
public THIS enable(JsonParser.Feature f, boolean state) {
_mapperConfig.configure(f, true);
return _this();
}
public THIS enable(JsonGenerator.Feature f, boolean state) {
_mapperConfig.configure(f, true);
return _this();
}
public THIS disable(JsonParser.Feature f, boolean state) {
_mapperConfig.configure(f, false);
return _this();
}
public THIS disable(JsonGenerator.Feature f, boolean state) {
_mapperConfig.configure(f, false);
return _this();
}
public THIS configure(JsonParser.Feature f, boolean state) {
_mapperConfig.configure(f, state);
return _this();
}
public THIS configure(JsonGenerator.Feature f, boolean state) {
_mapperConfig.configure(f, state);
return _this();
}
/*
/**********************************************************
/* Abstract methods sub-classes need to implement
/**********************************************************
*/
/**
* Helper method used to check whether given media type
* is supported by this provider for read operations
* (when binding input data such as POST body).
*
* Default implementation simply calls {@link #hasMatchingMediaType}.
*
* @since 2.3
*/
protected boolean hasMatchingMediaTypeForReading(MediaType mediaType) {
return hasMatchingMediaType(mediaType);
}
/**
* Helper method used to check whether given media type
* is supported by this provider for writing operations,
* such as when converting response object to response
* body of request (like GET or POST).
*
* Default implementation simply calls {@link #hasMatchingMediaType}.
*
* @since 2.3
*/
protected boolean hasMatchingMediaTypeForWriting(MediaType mediaType) {
return hasMatchingMediaType(mediaType);
}
/**
* Helper method used to check whether given media type
* is supported by this provider.
*
* @since 2.2
*/
protected abstract boolean hasMatchingMediaType(MediaType mediaType);
protected abstract MAPPER _locateMapperViaProvider(Class> type, MediaType mediaType);
protected EP_CONFIG _configForReading(MAPPER mapper,
Annotation[] annotations, Class> defaultView)
{
// ObjectReader r = _readerInjector.getAndClear();
ObjectReader r;
if (defaultView != null) {
r = mapper.readerWithView(defaultView);
} else {
r = mapper.reader();
}
return _configForReading(r, annotations);
}
protected EP_CONFIG _configForWriting(MAPPER mapper,
Annotation[] annotations, Class> defaultView)
{
// ObjectWriter w = _writerInjector.getAndClear();
ObjectWriter w;
if (defaultView != null) {
w = mapper.writerWithView(defaultView);
} else {
w = mapper.writer();
}
return _configForWriting(w, annotations);
}
/**
* @deprecated Since 2.3, use variant that takes explicit defaultView
*/
@Deprecated
protected EP_CONFIG _configForReading(MAPPER mapper, Annotation[] annotations) {
return _configForReading(mapper, annotations, _defaultReadView);
}
/**
* @deprecated Since 2.3, use variant that takes explicit defaultView
*/
@Deprecated
protected EP_CONFIG _configForWriting(MAPPER mapper, Annotation[] annotations) {
return _configForWriting(mapper, annotations, _defaultWriteView);
}
protected abstract EP_CONFIG _configForReading(ObjectReader reader,
Annotation[] annotations);
protected abstract EP_CONFIG _configForWriting(ObjectWriter writer,
Annotation[] annotations);
/*
/**********************************************************
/* Partial MessageBodyWriter impl
/**********************************************************
*/
/**
* Method that JAX-RS container calls to try to figure out
* serialized length of given value. Since computation of
* this length is about as expensive as serialization itself,
* implementation will return -1 to denote "not known", so
* that container will determine length from actual serialized
* output (if needed).
*/
@Override
public long getSize(Object value, Class> type, Type genericType, Annotation[] annotations, MediaType mediaType)
{
/* In general figuring output size requires actual writing; usually not
* worth it to write everything twice.
*/
return -1;
}
/**
* Method that JAX-RS container calls to try to check whether
* given value (of specified type) can be serialized by
* this provider.
* Implementation will first check that expected media type is
* expected one (by call to {@link #hasMatchingMediaType}); then verify
* that type is not one of "untouchable" types (types we will never
* automatically handle), and finally that there is a serializer
* for type (iff {@link #checkCanSerialize} has been called with
* true argument -- otherwise assumption is there will be a handler)
*/
@Override
public boolean isWriteable(Class> type, Type genericType, Annotation[] annotations, MediaType mediaType)
{
if (!hasMatchingMediaType(mediaType)) {
return false;
}
Boolean customUntouchable = _findCustomUntouchable(type);
if (customUntouchable != null) {
// negation: Boolean.TRUE means untouchable -> can not write
return !customUntouchable.booleanValue();
}
/* Ok: looks like we must weed out some core types here; ones that
* make no sense to try to bind from JSON:
*/
if (_untouchables.contains(new ClassKey(type))) {
return false;
}
// but some are interface/abstract classes, so
for (Class> cls : _unwritableClasses) {
if (cls.isAssignableFrom(type)) {
return false;
}
}
// Also: if we really want to verify that we can deserialize, we'll check:
if (_cfgCheckCanSerialize) {
if (!locateMapper(type, mediaType).canSerialize(type)) {
return false;
}
}
return true;
}
/**
* Method that JAX-RS container calls to serialize given value.
*/
@Override
public void writeTo(Object value, Class> type, Type genericType, Annotation[] annotations,
MediaType mediaType,
MultivaluedMap httpHeaders, OutputStream entityStream)
throws IOException
{
AnnotationBundleKey key = new AnnotationBundleKey(annotations, type);
EP_CONFIG endpoint;
synchronized (_writers) {
endpoint = _writers.get(key);
}
// not yet resolved (or not cached any more)? Resolve!
if (endpoint == null) {
MAPPER mapper = locateMapper(type, mediaType);
endpoint = _configForWriting(mapper, annotations, _defaultWriteView);
// and cache for future reuse
synchronized (_writers) {
_writers.put(key.immutableKey(), endpoint);
}
}
// Any headers we should write?
_modifyHeaders(value, type, genericType, annotations, httpHeaders, endpoint);
ObjectWriter writer = endpoint.getWriter();
// Where can we find desired encoding? Within HTTP headers?
JsonEncoding enc = findEncoding(mediaType, httpHeaders);
JsonGenerator g = _createGenerator(writer, entityStream, enc);
boolean ok = false;
try {
// Want indentation?
if (writer.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
g.useDefaultPrettyPrinter();
}
JavaType rootType = null;
if (genericType != null && value != null) {
/* 10-Jan-2011, tatu: as per [JACKSON-456], it's not safe to just force root
* type since it prevents polymorphic type serialization. Since we really
* just need this for generics, let's only use generic type if it's truly
* generic.
*/
if (genericType.getClass() != Class.class) { // generic types are other impls of 'java.lang.reflect.Type'
/* This is still not exactly right; should root type be further
* specialized with 'value.getClass()'? Let's see how well this works before
* trying to come up with more complete solution.
*/
rootType = writer.getTypeFactory().constructType(genericType);
/* 26-Feb-2011, tatu: To help with [JACKSON-518], we better recognize cases where
* type degenerates back into "Object.class" (as is the case with plain TypeVariable,
* for example), and not use that.
*/
if (rootType.getRawClass() == Object.class) {
rootType = null;
}
}
}
// Most of the configuration now handled through EndpointConfig, ObjectWriter
// but we may need to force root type:
if (rootType != null) {
writer = writer.withType(rootType);
}
value = endpoint.modifyBeforeWrite(value);
// [Issue#32]: allow modification by filter-injectible thing
ObjectWriterModifier mod = ObjectWriterInjector.getAndClear();
if (mod != null) {
writer = mod.modify(endpoint, httpHeaders, value, writer, g);
}
writer.writeValue(g, value);
ok = true;
} finally {
if (ok) {
g.close();
} else {
try {
g.close();
} catch (Exception e) { }
}
}
}
/**
* Helper method to use for determining desired output encoding.
* For now, will always just use UTF-8...
*/
protected JsonEncoding findEncoding(MediaType mediaType, MultivaluedMap httpHeaders)
{
return JsonEncoding.UTF8;
}
/**
* Overridable method used for adding optional response headers before
* serializing response object.
*/
protected void _modifyHeaders(Object value, Class> type, Type genericType, Annotation[] annotations,
MultivaluedMap httpHeaders,
EP_CONFIG endpoint)
throws IOException
{
// [Issue#6]: Add "nosniff" header?
if (isEnabled(JaxRSFeature.ADD_NO_SNIFF_HEADER)) {
httpHeaders.add(HEADER_CONTENT_TYPE_OPTIONS, "nosniff");
}
}
/**
* Overridable helper method called to create a {@link JsonGenerator} for writing
* contents into given raw {@link OutputStream}.
*
* @since 2.3
*/
protected JsonGenerator _createGenerator(ObjectWriter writer, OutputStream rawStream, JsonEncoding enc)
throws IOException
{
JsonGenerator g = writer.getFactory().createGenerator(rawStream, enc);
// Important: we are NOT to close the underlying stream after
// mapping, so we need to instruct generator
g.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
return g;
}
/*
/**********************************************************
/* MessageBodyReader impl
/**********************************************************
*/
/**
* Method that JAX-RS container calls to try to check whether
* values of given type (and media type) can be deserialized by
* this provider.
* Implementation will first check that expected media type is
* a JSON type (via call to {@link #hasMatchingMediaType});
* then verify
* that type is not one of "untouchable" types (types we will never
* automatically handle), and finally that there is a deserializer
* for type (iff {@link #checkCanDeserialize} has been called with
* true argument -- otherwise assumption is there will be a handler)
*/
@Override
public boolean isReadable(Class> type, Type genericType, Annotation[] annotations, MediaType mediaType)
{
if (!hasMatchingMediaType(mediaType)) {
return false;
}
Boolean customUntouchable = _findCustomUntouchable(type);
if (customUntouchable != null) {
// negation: Boolean.TRUE means untouchable -> can not write
return !customUntouchable.booleanValue();
}
/* Ok: looks like we must weed out some core types here; ones that
* make no sense to try to bind from JSON:
*/
if (_untouchables.contains(new ClassKey(type))) {
return false;
}
// and there are some other abstract/interface types to exclude too:
for (Class> cls : _unreadableClasses) {
if (cls.isAssignableFrom(type)) {
return false;
}
}
// Finally: if we really want to verify that we can serialize, we'll check:
if (_cfgCheckCanSerialize) {
if (_isSpecialReadable(type)) {
return true;
}
ObjectMapper mapper = locateMapper(type, mediaType);
if (!mapper.canDeserialize(mapper.constructType(type))) {
return false;
}
}
return true;
}
/**
* Method that JAX-RS container calls to deserialize given value.
*/
@Override
public Object readFrom(Class type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap httpHeaders,
InputStream entityStream)
throws IOException
{
AnnotationBundleKey key = new AnnotationBundleKey(annotations, type);
EP_CONFIG endpoint;
synchronized (_readers) {
endpoint = _readers.get(key);
}
// not yet resolved (or not cached any more)? Resolve!
if (endpoint == null) {
MAPPER mapper = locateMapper(type, mediaType);
endpoint = _configForReading(mapper, annotations, _defaultReadView);
// and cache for future reuse
synchronized (_readers) {
_readers.put(key.immutableKey(), endpoint);
}
}
ObjectReader reader = endpoint.getReader();
JsonParser jp = _createParser(reader, entityStream);
// If null is returned, considered to be empty stream
// 05-Apr-2014, tatu: As per [Issue#49], behavior here is configurable.
if (jp == null || jp.nextToken() == null) {
if (JaxRSFeature.ALLOW_EMPTY_INPUT.enabledIn(_jaxRSFeatures)) {
return null;
}
/* 05-Apr-2014, tatu: Trick-ee. NoContentFoundException only available in JAX-RS 2.0...
* so need bit of obfuscated code to reach it.
*/
IOException fail = _noContentExceptionRef.get();
if (fail == null) {
fail = _createNoContentException();
}
throw fail;
}
// [Issue#1]: allow 'binding' to JsonParser
if (((Class>) type) == JsonParser.class) {
return jp;
}
final JavaType resolvedType = reader.getTypeFactory().constructType(genericType);
reader = reader.withType(resolvedType);
// [Issue#32]: allow modification by filter-injectible thing
ObjectReaderModifier mod = ObjectReaderInjector.getAndClear();
if (mod != null) {
reader = mod.modify(endpoint, httpHeaders, resolvedType, reader, jp);
}
return reader.readValue(jp);
}
/**
* Overridable helper method called to create a {@link JsonParser} for reading
* contents of given raw {@link InputStream}.
* May return null to indicate that Stream is empty; that is, contains no
* content.
*
* @since 2.2
*/
protected JsonParser _createParser(ObjectReader reader, InputStream rawStream)
throws IOException
{
JsonParser p = reader.getFactory().createParser(rawStream);
// Important: we are NOT to close the underlying stream after
// mapping, so we need to instruct parser:
p.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
return p;
}
/*
/**********************************************************
/* Overridable helper methods
/**********************************************************
*/
/**
* Method called to locate {@link ObjectMapper} to use for serialization
* and deserialization. If an instance has been explicitly defined by
* {@link #setMapper} (or non-null instance passed in constructor), that
* will be used.
* If not, will try to locate it using standard JAX-RS
* ContextResolver
mechanism, if it has been properly configured
* to access it (by JAX-RS runtime).
* Finally, if no mapper is found, will return a default unconfigured
* {@link ObjectMapper} instance (one constructed with default constructor
* and not modified in any way)
*
* @param type Class of object being serialized or deserialized;
* not checked at this point, since it is assumed that unprocessable
* classes have been already weeded out,
* but will be passed to ContextResolver
as is.
* @param mediaType Declared media type for the instance to process:
* not used by this method,
* but will be passed to ContextResolver
as is.
*/
public MAPPER locateMapper(Class> type, MediaType mediaType)
{
// First: were we configured with a specific instance?
MAPPER m = _mapperConfig.getConfiguredMapper();
if (m == null) {
// If not, maybe we can get one configured via context?
m = _locateMapperViaProvider(type, mediaType);
if (m == null) {
// If not, let's get the fallback default instance
m = _mapperConfig.getDefaultMapper();
}
}
return m;
}
/**
* Overridable helper method used to allow handling of somewhat special
* types for reading
*
* @since 2.2
*/
protected boolean _isSpecialReadable(Class> type) {
return JsonParser.class == type;
}
/**
* @since 2.4
*/
protected IOException _createNoContentException()
{
Class> cls = null;
try {
cls = Class.forName(CLASS_NAME_NO_CONTENT_EXCEPTION);
Constructor> ctor = cls.getDeclaredConstructor(String.class);
if (ctor != null) {
return (IOException) ctor.newInstance(NO_CONTENT_MESSAGE);
}
} catch (Exception e) { // no can do...
}
return new IOException(NO_CONTENT_MESSAGE);
}
/*
/**********************************************************
/* Private/sub-class helper methods
/**********************************************************
*/
protected static boolean _containedIn(Class> mainType, HashSet set)
{
if (set != null) {
ClassKey key = new ClassKey(mainType);
// First: type itself?
if (set.contains(key)) return true;
// Then supertypes (note: will not contain Object.class)
for (Class> cls : findSuperTypes(mainType, null)) {
key.reset(cls);
if (set.contains(key)) return true;
}
}
return false;
}
protected Boolean _findCustomUntouchable(Class> mainType)
{
if (_cfgCustomUntouchables != null) {
ClassKey key = new ClassKey(mainType);
// First: type itself?
Boolean b = _cfgCustomUntouchables.get(key);
if (b != null) {
return b;
}
// Then supertypes (note: will not contain Object.class)
for (Class> cls : findSuperTypes(mainType, null)) {
key.reset(cls);
b = _cfgCustomUntouchables.get(key);
if (b != null) {
return b;
}
}
}
return null;
}
protected static List> findSuperTypes(Class> cls, Class> endBefore)
{
return findSuperTypes(cls, endBefore, new ArrayList>(8));
}
protected static List> findSuperTypes(Class> cls, Class> endBefore, List> result)
{
_addSuperTypes(cls, endBefore, result, false);
return result;
}
protected static void _addSuperTypes(Class> cls, Class> endBefore, Collection> result, boolean addClassItself)
{
if (cls == endBefore || cls == null || cls == Object.class) {
return;
}
if (addClassItself) {
if (result.contains(cls)) { // already added, no need to check supers
return;
}
result.add(cls);
}
for (Class> intCls : cls.getInterfaces()) {
_addSuperTypes(intCls, endBefore, result, true);
}
_addSuperTypes(cls.getSuperclass(), endBefore, result, true);
}
@SuppressWarnings("unchecked")
private final THIS _this() {
return (THIS) this;
}
}
0000775 0000000 0000000 00000000000 12373533575 0034502 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/cfg AnnotationBundleKey.java 0000664 0000000 0000000 00000010504 12373533575 0041262 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/cfg package com.fasterxml.jackson.jaxrs.cfg;
import java.lang.annotation.Annotation;
/**
* Helper class used to allow efficient caching of information,
* given a sequence of Annotations.
* This is mostly used for reusing introspected information on
* JAX-RS end points.
*
* @since 2.2
*/
public final class AnnotationBundleKey
{
private final static Annotation[] NO_ANNOTATIONS = new Annotation[0];
private final Annotation[] _annotations;
/**
* We also seem to need the type as part of the key (as per [Issue#11]);
* hopefully that and annotations are enough (if not, may need to reconsider
* the way caching is done, and possibly only cache derivation of annotations,
* not mapper or reader/writer).
*/
private final Class> _type;
private final boolean _annotationsCopied;
private final int _hashCode;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
/**
* @deprecated Since 2.2.2: use variant that takes explicit Class
*/
@Deprecated
public AnnotationBundleKey(Annotation[] annotations)
{
// could use a private inner class, but this'll do for now; no one should call anyway
this(annotations, AnnotationBundleKey.class);
}
public AnnotationBundleKey(Annotation[] annotations, Class> type)
{
_type = type;
// getting hash of name is faster than Class.hashCode() just because latter uses system identity hash:
final int typeHash = type.getName().hashCode();
if (annotations == null || annotations.length == 0) {
annotations = NO_ANNOTATIONS;
_annotationsCopied = true;
_hashCode = typeHash;
} else {
_annotationsCopied = false;
_hashCode = calcHash(annotations) ^ typeHash;
}
_annotations = annotations;
}
private AnnotationBundleKey(Annotation[] annotations, Class> type, int hashCode)
{
_annotations = annotations;
_annotationsCopied = true;
_type = type;
_hashCode = hashCode;
}
private final static int calcHash(Annotation[] annotations)
{
/* hmmh. Can't just base on Annotation type; chances are that Annotation
* instances use identity hash, which has to do.
*/
final int len = annotations.length;
int hash = len;
for (int i = 0; i < len; ++i) {
hash = (hash * 31) + annotations[i].hashCode();
}
return hash;
}
/**
* Method called to create a safe immutable copy of the key; used when
* adding entry with this key -- lookups are ok without calling the method.
*/
public AnnotationBundleKey immutableKey() {
if (_annotationsCopied) {
return this;
}
int len = _annotations.length;
Annotation[] newAnnotations = new Annotation[len];
System.arraycopy(_annotations, 0, newAnnotations, 0, len);
return new AnnotationBundleKey(newAnnotations, _type, _hashCode);
}
/*
/**********************************************************
/* Overridden methods
/**********************************************************
*/
@Override
public int hashCode() {
return _hashCode;
}
@Override
public String toString() {
return "[Annotations: "+_annotations.length+", type: "
+_type.getName()+", hash 0x"+Integer.toHexString(_hashCode)
+", copied: "+_annotationsCopied+"]";
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
AnnotationBundleKey other = (AnnotationBundleKey) o;
if ((other._hashCode != _hashCode) || (other._type != _type)) {
return false;
}
return _equals(other._annotations);
}
private final boolean _equals(Annotation[] otherAnn)
{
final int len = _annotations.length;
if (otherAnn.length != len) {
return false;
}
for (int i = 0; i < len; ++i) {
if (_annotations[i] != otherAnn[i]) {
return false;
}
}
return true;
}
}
Annotations.java 0000664 0000000 0000000 00000001107 12373533575 0037641 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/cfg package com.fasterxml.jackson.jaxrs.cfg;
/**
* Enumeration that defines standard annotation sets available for configuring
* data binding aspects.
*
* @since 2.2 (earlier located in actual datatype-specific modules)
*/
public enum Annotations {
/**
* Standard Jackson annotations, defined in Jackson core and databind
* packages
*/
JACKSON,
/**
* Standard JAXB annotations, used in a way that approximates expected
* definitions (since JAXB defines XML aspects, not all features map
* well to JSON handling)
*/
JAXB
;
}
EndpointConfigBase.java 0000664 0000000 0000000 00000012573 12373533575 0041056 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/cfg package com.fasterxml.jackson.jaxrs.cfg;
import java.lang.annotation.Annotation;
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.jaxrs.annotation.JacksonFeatures;
/**
* Container class for figuring out annotation-based configuration
* for JAX-RS end points.
*/
public abstract class EndpointConfigBase>
{
// // General configuration
protected Class> _activeView;
protected String _rootName;
// // Deserialization-only config
protected DeserializationFeature[] _deserEnable;
protected DeserializationFeature[] _deserDisable;
protected ObjectReader _reader;
// // Serialization-only config
protected SerializationFeature[] _serEnable;
protected SerializationFeature[] _serDisable;
protected ObjectWriter _writer;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
protected EndpointConfigBase() { }
@SuppressWarnings("unchecked")
protected THIS add(Annotation[] annotations, boolean forWriting)
{
if (annotations != null) {
for (Annotation annotation : annotations) {
addAnnotation(annotation.annotationType(), annotation, forWriting);
}
}
return (THIS) this;
}
protected void addAnnotation(Class extends Annotation> type,
Annotation annotation, boolean forWriting)
{
if (type == JsonView.class) {
// Can only use one view; but if multiple defined, use first (no exception)
Class>[] views = ((JsonView) annotation).value();
_activeView = (views.length > 0) ? views[0] : null;
} else if (type == JacksonFeatures.class) {
JacksonFeatures feats = (JacksonFeatures) annotation;
if (forWriting) {
_serEnable = nullIfEmpty(feats.serializationEnable());
_serDisable = nullIfEmpty(feats.serializationDisable());
} else {
_deserEnable = nullIfEmpty(feats.deserializationEnable());
_deserDisable = nullIfEmpty(feats.deserializationDisable());
}
} else if (type == JsonRootName.class) {
_rootName = ((JsonRootName) annotation).value();
} else if (type == JacksonAnnotationsInside.class) {
// skip; processed below (in parent), so encountering here is of no use
} else {
// For all unrecognized types, check meta-annotation(s) to see if they are bundles
JacksonAnnotationsInside inside = type.getAnnotation(JacksonAnnotationsInside.class);
if (inside != null) {
add(type.getAnnotations(), forWriting);
}
}
}
@SuppressWarnings("unchecked")
protected THIS initReader(ObjectReader reader)
{
if (_activeView != null) {
reader = reader.withView(_activeView);
}
if (_rootName != null) {
reader = reader.withRootName(_rootName);
}
// Then deser features
if (_deserEnable != null) {
reader = reader.withFeatures(_deserEnable);
}
if (_deserDisable != null) {
reader = reader.withoutFeatures(_deserDisable);
}
_reader = reader;
return (THIS) this;
}
@SuppressWarnings("unchecked")
protected THIS initWriter(ObjectWriter writer)
{
if (_activeView != null) {
writer = writer.withView(_activeView);
}
if (_rootName != null) {
writer = writer.withRootName(_rootName);
}
// Then features
if (_serEnable != null) {
writer = writer.withFeatures(_serEnable);
}
if (_serDisable != null) {
writer = writer.withoutFeatures(_serDisable);
}
_writer = writer;
return (THIS) this;
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
/**
* @since 2.3
*/
public String getRootName() {
return _rootName;
}
/**
* @since 2.3
*/
public Class> getActiveView() {
return _activeView;
}
public final ObjectReader getReader() {
if (_reader == null) { // sanity check, should never happen
throw new IllegalStateException();
}
return _reader;
}
public final ObjectWriter getWriter() {
if (_writer == null) { // sanity check, should never happen
throw new IllegalStateException();
}
return _writer;
}
/*
/**********************************************************
/* Value modifications
/**********************************************************
*/
public abstract Object modifyBeforeWrite(Object value);
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected static T[] nullIfEmpty(T[] arg) {
if (arg == null || arg.length == 0) {
return null;
}
return arg;
}
}
JaxRSFeature.java 0000664 0000000 0000000 00000004317 12373533575 0037655 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/cfg package com.fasterxml.jackson.jaxrs.cfg;
import com.fasterxml.jackson.databind.cfg.ConfigFeature;
/**
* Enumeration that defines simple on/off features that can be
* used on all Jackson JAX-RS providers, regardless of
* underlying data format.
*/
public enum JaxRSFeature implements ConfigFeature
{
/*
/******************************************************
/* Input handling
/******************************************************
*/
/**
* Feature related to
* Issue #49 :
* whether empty input is considered legal or not.
* If set to true, empty content is allowed and will be read as Java 'null': if false,
* an {@link java.io.IOException} will be thrown.
*
* NOTE: in case of JAX-RS 2.0, specific exception will be javax.ws.rs.core.NoContentException
;
* but this is not defined in JAX-RS 1.x.
*/
ALLOW_EMPTY_INPUT(true),
/*
/******************************************************
/* HTTP headers
/******************************************************
*/
/**
* Feature that can be enabled to make provider automatically
* add "nosniff" (see
* this entry
* for details
*
* Feature is disabled by default.
*/
ADD_NO_SNIFF_HEADER(false),
/*
/******************************************************
/* Other
/******************************************************
*/
;
private final boolean _defaultState;
private JaxRSFeature(boolean defaultState) {
_defaultState = defaultState;
}
public static int collectDefaults() {
int flags = 0;
for (JaxRSFeature f : values()) {
if (f.enabledByDefault()) { flags |= f.getMask(); }
}
return flags;
}
@Override
public boolean enabledByDefault() { return _defaultState; }
@Override
public int getMask() { return (1 << ordinal()); }
public boolean enabledIn(int flags) { return (flags & getMask()) != 0; }
}
MapperConfiguratorBase.java 0000664 0000000 0000000 00000007706 12373533575 0041761 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/cfg package com.fasterxml.jackson.jaxrs.cfg;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
/**
* Helper class used to encapsulate details of configuring an
* {@link ObjectMapper} instance to be used for data binding, as
* well as accessing it.
*/
public abstract class MapperConfiguratorBase,
MAPPER extends ObjectMapper
>
{
/**
* Mapper provider was constructed with if any, or that was constructed
* due to a call to explicitly configure mapper.
* If defined (explicitly or implicitly) it will be used, instead
* of using provider-based lookup.
*/
protected MAPPER _mapper;
/**
* If no mapper was specified when constructed, and no configuration
* calls are made, a default mapper is constructed. The difference
* between default mapper and regular one is that default mapper
* is only used if no mapper is found via provider lookup.
*/
protected MAPPER _defaultMapper;
/**
* Annotations set to use by default; overridden by explicit call
* to {@link #setAnnotationsToUse}
*/
protected Annotations[] _defaultAnnotationsToUse;
/**
* To support optional dependency to Jackson JAXB annotations module
* (needed iff JAXB annotations are used for configuration)
*/
protected Class extends AnnotationIntrospector> _jaxbIntrospectorClass;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public MapperConfiguratorBase(MAPPER mapper, Annotations[] defaultAnnotations)
{
_mapper = mapper;
_defaultAnnotationsToUse = defaultAnnotations;
}
/*
/**********************************************************
/* Abstract methods to implement
/***********************************************************
*/
/**
* Method that locates, configures and returns {@link ObjectMapper} to use
*/
public abstract MAPPER getConfiguredMapper();
public abstract MAPPER getDefaultMapper();
/**
* Helper method that will ensure that there is a configurable non-default
* mapper (constructing an instance if one didn't yet exit), and return
* that mapper.
*/
protected abstract MAPPER mapper();
protected abstract AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse);
/*
/***********************************************************
/* Configuration methods
/***********************************************************
*/
public synchronized final void setMapper(MAPPER m) {
_mapper = m;
}
public synchronized final void setAnnotationsToUse(Annotations[] annotationsToUse) {
_setAnnotations(mapper(), annotationsToUse);
}
public synchronized final void configure(DeserializationFeature f, boolean state) {
mapper().configure(f, state);
}
public synchronized final void configure(SerializationFeature f, boolean state) {
mapper().configure(f, state);
}
public synchronized final void configure(JsonParser.Feature f, boolean state) {
mapper().configure(f, state);
}
public synchronized final void configure(JsonGenerator.Feature f, boolean state) {
mapper().configure(f, state);
}
/*
/***********************************************************
/* Helper methods for sub-classes
/***********************************************************
*/
protected final void _setAnnotations(ObjectMapper mapper, Annotations[] annotationsToUse)
{
AnnotationIntrospector intr;
if (annotationsToUse == null || annotationsToUse.length == 0) {
intr = AnnotationIntrospector.nopInstance();
} else {
intr = _resolveIntrospectors(annotationsToUse);
}
mapper.setAnnotationIntrospector(intr);
}
}
ObjectReaderInjector.java 0000664 0000000 0000000 00000002520 12373533575 0041373 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/cfg package com.fasterxml.jackson.jaxrs.cfg;
import java.util.concurrent.atomic.AtomicBoolean;
import com.fasterxml.jackson.databind.*;
/**
* Based on ideas from [Issue#32], this class allows registering a
* modifier ({@link ObjectReaderModifier}) that can be used to
* reconfigure {@link ObjectReader}
* that JAX-RS Resource will use for reading input into Java Objects.
* Usually this class is accessed from a Servlet or JAX-RS filter
* before execution reaches resource.
*
* @since 2.3
*/
public class ObjectReaderInjector
{
protected static final ThreadLocal _threadLocal = new ThreadLocal();
/**
* Simple marker used to optimize out {@link ThreadLocal} access in cases
* where this feature is not being used
*/
protected static final AtomicBoolean _hasBeenSet = new AtomicBoolean(false);
private ObjectReaderInjector() { }
public static void set(ObjectReaderModifier mod) {
_hasBeenSet.set(true);
_threadLocal.set(mod);
}
public static ObjectReaderModifier get() {
return _hasBeenSet.get() ? _threadLocal.get() : null;
}
public static ObjectReaderModifier getAndClear() {
ObjectReaderModifier mod = get();
if (mod != null) {
_threadLocal.remove();
}
return mod;
}
}
ObjectReaderModifier.java 0000664 0000000 0000000 00000001670 12373533575 0041361 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/cfg package com.fasterxml.jackson.jaxrs.cfg;
import java.io.IOException;
import javax.ws.rs.core.MultivaluedMap;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
/**
* @since 2.3
*/
public abstract class ObjectReaderModifier
{
/**
* Method called to let modifier make any changes it wants to to objects
* used for reading request objects for specified endpoint.
*
* @param endpoint End point for which reader is used
* @param httpHeaders HTTP headers sent with request (read-only)
* @param resultType Type that input is to be bound to
* @param r ObjectReader as constructed for endpoint, type to handle
* @param p Parser to use for reading content
*/
public abstract ObjectReader modify(EndpointConfigBase> endpoint,
MultivaluedMap httpHeaders,
JavaType resultType, ObjectReader r, JsonParser p)
throws IOException;
}
ObjectWriterInjector.java 0000664 0000000 0000000 00000002274 12373533575 0041453 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/cfg package com.fasterxml.jackson.jaxrs.cfg;
import java.util.concurrent.atomic.AtomicBoolean;
import com.fasterxml.jackson.databind.*;
/**
* Based on ideas from [Issue#32], this class allows "overriding" of {@link ObjectWriter}
* that JAX-RS Resource will use; usually this is done from a Servlet or JAX-RS filter
* before execution reaches resource.
*
* @since 2.3
*/
public class ObjectWriterInjector
{
protected static final ThreadLocal _threadLocal = new ThreadLocal();
/**
* Simple marker used to optimize out {@link ThreadLocal} access in cases
* where this feature is not being used
*/
protected static final AtomicBoolean _hasBeenSet = new AtomicBoolean(false);
private ObjectWriterInjector() { }
public static void set(ObjectWriterModifier mod) {
_hasBeenSet.set(true);
_threadLocal.set(mod);
}
public static ObjectWriterModifier get() {
return _hasBeenSet.get() ? _threadLocal.get() : null;
}
public static ObjectWriterModifier getAndClear() {
ObjectWriterModifier mod = get();
if (mod != null) {
_threadLocal.remove();
}
return mod;
}
}
ObjectWriterModifier.java 0000664 0000000 0000000 00000001325 12373533575 0041430 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/cfg package com.fasterxml.jackson.jaxrs.cfg;
import java.io.IOException;
import javax.ws.rs.core.MultivaluedMap;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
/**
* @since 2.3
*/
public abstract class ObjectWriterModifier
{
/**
* Method called to let modifier make any changes it wants to to objects
* used for writing response for specified endpoint.
*
* @param responseHeaders HTTP headers being returned with response (mutable)
*/
public abstract ObjectWriter modify(EndpointConfigBase> endpoint,
MultivaluedMap responseHeaders,
Object valueToWrite, ObjectWriter w, JsonGenerator g)
throws IOException;
}
0000775 0000000 0000000 00000000000 12373533575 0034720 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/util ClassKey.java 0000664 0000000 0000000 00000005026 12373533575 0037304 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/util package com.fasterxml.jackson.jaxrs.util;
/**
* Efficient key class, used instead of using Class
.
* The reason for having a separate key class instead of
* directly using {@link Class} as key is mostly
* to allow for redefining hashCode
method --
* for some strange reason, {@link Class} does not
* redefine {@link Object#hashCode} and thus uses identity
* hash, which is pretty slow. This makes key access using
* {@link Class} unnecessarily slow.
*
* Note: since class is not strictly immutable, caller must
* know what it is doing, if changing field values.
*
* @since 2.2
*/
public final class ClassKey
implements Comparable
{
private String _className;
private Class> _class;
/**
* Let's cache hash code straight away, since we are
* almost certain to need it.
*/
private int _hashCode;
public ClassKey()
{
_class = null;
_className = null;
_hashCode = 0;
}
public ClassKey(Class> clz)
{
_class = clz;
_className = clz.getName();
_hashCode = _className.hashCode();
}
public void reset(Class> clz)
{
_class = clz;
_className = clz.getName();
_hashCode = _className.hashCode();
}
/*
/**********************************************************
/* Comparable
/**********************************************************
*/
// Just need to sort by name, ok to collide (unless used in TreeMap/Set!)
@Override
public int compareTo(ClassKey other) {
return _className.compareTo(other._className);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
ClassKey other = (ClassKey) o;
/* Is it possible to have different Class object for same name + class loader combo?
* Let's assume answer is no: if this is wrong, will need to uncomment following functionality
*/
/*
return (other._className.equals(_className))
&& (other._class.getClassLoader() == _class.getClassLoader());
*/
return other._class == _class;
}
@Override public int hashCode() { return _hashCode; }
@Override public String toString() { return _className; }
}
EndpointAsBeanProperty.java 0000664 0000000 0000000 00000003076 12373533575 0042170 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/util package com.fasterxml.jackson.jaxrs.util;
import java.lang.annotation.Annotation;
import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.PropertyMetadata;
import com.fasterxml.jackson.databind.PropertyName;
import com.fasterxml.jackson.databind.introspect.AnnotationMap;
/**
* {@link BeanProperty} implementation used for passing annotations
* from JAX-RS endpoint into Jackson. This tries to imitate behavior
* one would get if actual resource method was used as POJO property;
* ideally this would be how implementation works but due JAX-RS API
* limitations, we are only given annotations associated, and that
* has to do.
*/
public class EndpointAsBeanProperty
extends BeanProperty.Std
{
public final static PropertyName ENDPOINT_NAME = new PropertyName("JAX-RS/endpoint");
private final static AnnotationMap NO_ANNOTATIONS = new AnnotationMap();
public final AnnotationMap _annotations;
public EndpointAsBeanProperty(JavaType type, Annotation[] annotations)
{
// TODO: find and pass wrapper; isRequired marker?
super(ENDPOINT_NAME, type, /*PropertyName wrapperName*/ null,
null, null, PropertyMetadata.STD_OPTIONAL);
boolean hasAnn = (annotations != null && annotations.length > 0);
if (hasAnn) {
_annotations = new AnnotationMap();
for (Annotation a : annotations) {
_annotations.add(a);
}
} else {
_annotations = NO_ANNOTATIONS;
}
}
}
LRUMap.java 0000664 0000000 0000000 00000001116 12373533575 0036662 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/base/src/main/java/com/fasterxml/jackson/jaxrs/util package com.fasterxml.jackson.jaxrs.util;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Helper for simple bounded LRU maps used for reusing lookup values.
*
* @since 2.2
*/
@SuppressWarnings("serial")
public class LRUMap extends LinkedHashMap
{
protected final int _maxEntries;
public LRUMap(int initialEntries, int maxEntries)
{
super(initialEntries, 0.8f, true);
_maxEntries = maxEntries;
}
@Override
protected boolean removeEldestEntry(Map.Entry eldest)
{
return size() > _maxEntries;
}
}
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/ 0000775 0000000 0000000 00000000000 12373533575 0024037 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/pom.xml 0000664 0000000 0000000 00000006352 12373533575 0025362 0 ustar 00root root 0000000 0000000
4.0.0
com.fasterxml.jackson.jaxrs
jackson-jaxrs-providers
2.4.2
jackson-jaxrs-cbor-provider
Jackson-JAXRS-CBOR
bundle
Functionality to handle CBOR encoded input/output for JAX-RS implementations (like Jersey and RESTeasy) using standard Jackson data binding.
com/fasterxml/jackson/jaxrs/cbor
${project.groupId}.cbor
${project.groupId}.cbor.*;version=${project.version}
javax.ws.rs
,javax.ws.rs.core
,javax.ws.rs.ext
,com.fasterxml.jackson.annotation
,com.fasterxml.jackson.core
,com.fasterxml.jackson.core.type
,com.fasterxml.jackson.core.util
,com.fasterxml.jackson.databind
,com.fasterxml.jackson.databind.introspect
,com.fasterxml.jackson.databind.type
,com.fasterxml.jackson.databind.util
,com.fasterxml.jackson.dataformat.cbor
,com.fasterxml.jackson.jaxrs.base
,com.fasterxml.jackson.jaxrs.cfg
,com.fasterxml.jackson.module.jaxb;resolution:=optional
jackson-jaxrs-base
${project.groupId}
${project.version}
com.fasterxml.jackson.core
jackson-core
${version.jackson.core}
com.fasterxml.jackson.core
jackson-databind
${version.jackson.core}
com.fasterxml.jackson.dataformat
jackson-dataformat-cbor
${version.jackson.cbor}
com.fasterxml.jackson.module
jackson-module-jaxb-annotations
${version.jackson.jaxb}
com.google.code.maven-replacer-plugin
replacer
process-packageVersion
process-sources
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/ 0000775 0000000 0000000 00000000000 12373533575 0024626 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/ 0000775 0000000 0000000 00000000000 12373533575 0025552 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/ 0000775 0000000 0000000 00000000000 12373533575 0026473 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/ 0000775 0000000 0000000 00000000000 12373533575 0027251 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/fasterxml/ 0000775 0000000 0000000 00000000000 12373533575 0031256 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/fasterxml/jackson/ 0000775 0000000 0000000 00000000000 12373533575 0032706 5 ustar 00root root 0000000 0000000 0000775 0000000 0000000 00000000000 12373533575 0033756 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/fasterxml/jackson/jaxrs 0000775 0000000 0000000 00000000000 12373533575 0034703 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/fasterxml/jackson/jaxrs/cbor CBOREndpointConfig.java 0000664 0000000 0000000 00000002534 12373533575 0041126 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/fasterxml/jackson/jaxrs/cbor package com.fasterxml.jackson.jaxrs.cbor;
import java.lang.annotation.Annotation;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.jaxrs.cfg.EndpointConfigBase;
/**
* Container class for figuring out annotation-based configuration
* for JAX-RS end points.
*/
public class CBOREndpointConfig
extends EndpointConfigBase
{
/*
/**********************************************************
/* Construction
/**********************************************************
*/
protected CBOREndpointConfig() { }
public static CBOREndpointConfig forReading(ObjectReader reader,
Annotation[] annotations)
{
return new CBOREndpointConfig()
.add(annotations, false)
.initReader(reader)
;
}
public static CBOREndpointConfig forWriting(ObjectWriter writer,
Annotation[] annotations)
{
CBOREndpointConfig config = new CBOREndpointConfig();
return config
.add(annotations, true)
.initWriter(writer)
;
}
// No need to override, fine as-is:
// protected void addAnnotation(Class extends Annotation> type, Annotation annotation, boolean forWriting)
@Override
public Object modifyBeforeWrite(Object value) {
// nothing to add
return value;
}
}
CBORMapperConfigurator.java 0000664 0000000 0000000 00000007432 12373533575 0042031 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/fasterxml/jackson/jaxrs/cbor package com.fasterxml.jackson.jaxrs.cbor;
import java.util.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
import com.fasterxml.jackson.jaxrs.cfg.MapperConfiguratorBase;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
/**
* Helper class used to encapsulate details of configuring an
* {@link ObjectMapper} instance to be used for data binding, as
* well as accessing it.
*/
public class CBORMapperConfigurator
extends MapperConfiguratorBase
{
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public CBORMapperConfigurator(ObjectMapper mapper, Annotations[] defAnnotations)
{
super(mapper, defAnnotations);
}
/**
* Method that locates, configures and returns {@link ObjectMapper} to use
*/
@Override
public synchronized ObjectMapper getConfiguredMapper() {
/* important: should NOT call mapper(); needs to return null
* if no instance has been passed or constructed
*/
return _mapper;
}
@Override
public synchronized ObjectMapper getDefaultMapper() {
if (_defaultMapper == null) {
_defaultMapper = new ObjectMapper(new CBORFactory());
_setAnnotations(_defaultMapper, _defaultAnnotationsToUse);
}
return _defaultMapper;
}
/*
/***********************************************************
/* Internal methods
/***********************************************************
*/
/**
* Helper method that will ensure that there is a configurable non-default
* mapper (constructing an instance if one didn't yet exit), and return
* that mapper.
*/
@Override
protected ObjectMapper mapper()
{
if (_mapper == null) {
_mapper = new ObjectMapper(new CBORFactory());
_setAnnotations(_mapper, _defaultAnnotationsToUse);
}
return _mapper;
}
@Override
protected AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse)
{
// Let's ensure there are no dups there first, filter out nulls
ArrayList intr = new ArrayList();
for (Annotations a : annotationsToUse) {
if (a != null) {
intr.add(_resolveIntrospector(a));
}
}
int count = intr.size();
if (count == 0) {
return AnnotationIntrospector.nopInstance();
}
AnnotationIntrospector curr = intr.get(0);
for (int i = 1, len = intr.size(); i < len; ++i) {
curr = AnnotationIntrospector.pair(curr, intr.get(i));
}
return curr;
}
protected AnnotationIntrospector _resolveIntrospector(Annotations ann)
{
switch (ann) {
case JACKSON:
return new JacksonAnnotationIntrospector();
case JAXB:
/* For this, need to use indirection just so that error occurs
* when we get here, and not when this class is being loaded
*/
try {
if (_jaxbIntrospectorClass == null) {
_jaxbIntrospectorClass = JaxbAnnotationIntrospector.class;
}
return _jaxbIntrospectorClass.newInstance();
} catch (Exception e) {
throw new IllegalStateException("Failed to instantiate JaxbAnnotationIntrospector: "+e.getMessage(), e);
}
default:
throw new IllegalStateException();
}
}
}
CBORMediaTypes.java 0000664 0000000 0000000 00000000546 12373533575 0040265 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/fasterxml/jackson/jaxrs/cbor package com.fasterxml.jackson.jaxrs.cbor;
import javax.ws.rs.core.MediaType;
public class CBORMediaTypes {
// Should be the official one, from CBOR spec
public static final String APPLICATION_JACKSON_CBOR = "application/cbor";
public static final MediaType APPLICATION_JACKSON_CBOR_TYPE = MediaType.valueOf(APPLICATION_JACKSON_CBOR);
}
JacksonCBORProvider.java 0000664 0000000 0000000 00000020301 12373533575 0041313 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/fasterxml/jackson/jaxrs/cbor package com.fasterxml.jackson.jaxrs.cbor;
import java.lang.annotation.Annotation;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import javax.ws.rs.ext.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import com.fasterxml.jackson.jaxrs.base.ProviderBase;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
/**
* Basic implementation of JAX-RS abstractions ({@link MessageBodyReader},
* {@link MessageBodyWriter}) needed for binding
* Smile ("application/x-jackson-smile") content to and from Java Objects ("POJO"s).
*
* Actual data binding functionality is implemented by {@link ObjectMapper}:
* mapper to use can be configured in multiple ways:
*
* By explicitly passing mapper to use in constructor
* By explictly setting mapper to use by {@link #setMapper}
* By defining JAX-RS Provider
that returns {@link ObjectMapper}s.
* By doing none of above, in which case a default mapper instance is
* constructed (and configured if configuration methods are called)
*
* The last method ("do nothing specific") is often good enough; explicit passing
* of Mapper is simple and explicit; and Provider-based method may make sense
* with Depedency Injection frameworks, or if Mapper has to be configured differently
* for different media types.
*
* Note that the default mapper instance will be automatically created if
* one of explicit configuration methods (like {@link #configure})
* is called: if so, Provider-based introspection is NOT used, but the
* resulting Mapper is used as configured.
*
* Note that there is also a sub-class -- ({@link JacksonJaxbCBORProvider}) -- that
* is configured by default to use both Jackson and JAXB annotations for configuration
* (base class when used as-is defaults to using just Jackson annotations)
*
* @author Tatu Saloranta
*/
@Provider
@Consumes(CBORMediaTypes.APPLICATION_JACKSON_CBOR)
@Produces(CBORMediaTypes.APPLICATION_JACKSON_CBOR)
public class JacksonCBORProvider
extends ProviderBase
{
/**
* Default annotation sets to use, if not explicitly defined during
* construction: only Jackson annotations are used for the base
* class. Sub-classes can use other settings.
*/
public final static Annotations[] BASIC_ANNOTATIONS = {
Annotations.JACKSON
};
/*
/**********************************************************
/* Context configuration
/**********************************************************
*/
/**
* Injectable context object used to locate configured
* instance of {@link ObjectMapper} to use for actual
* serialization.
*/
@Context
protected Providers _providers;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
/**
* Default constructor, usually used when provider is automatically
* configured to be used with JAX-RS implementation.
*/
public JacksonCBORProvider() {
this(null, BASIC_ANNOTATIONS);
}
/**
* @param annotationsToUse Annotation set(s) to use for configuring
* data binding
*/
public JacksonCBORProvider(Annotations... annotationsToUse)
{
this(null, annotationsToUse);
}
public JacksonCBORProvider(ObjectMapper mapper)
{
this(mapper, BASIC_ANNOTATIONS);
}
/**
* Constructor to use when a custom mapper (usually components
* like serializer/deserializer factories that have been configured)
* is to be used.
*
* @param annotationsToUse Sets of annotations (Jackson, JAXB) that provider should
* support
*/
public JacksonCBORProvider(ObjectMapper mapper, Annotations[] annotationsToUse)
{
super(new CBORMapperConfigurator(mapper, annotationsToUse));
}
/**
* Method that will return version information stored in and read from jar
* that contains this class.
*/
@Override
public Version version() {
return PackageVersion.VERSION;
}
/*
/**********************************************************
/* Abstract method impls
/**********************************************************
*/
/**
* @deprecated Since 2.2 use {@link #hasMatchingMediaType(MediaType)} instead
*/
@Deprecated
protected boolean isSmileType(MediaType mediaType) {
return hasMatchingMediaType(mediaType);
}
/**
* Helper method used to check whether given media type
* is Smile type or sub type.
* Current implementation essentially checks to see whether
* {@link MediaType#getSubtype} returns
* "smile" or something ending with "+smile".
*/
@Override
protected boolean hasMatchingMediaType(MediaType mediaType)
{
/* As suggested by Stephen D, there are 2 ways to check: either
* being as inclusive as possible (if subtype is "smile"), or
* exclusive (major type "application", minor type "smile").
* Let's start with inclusive one, hard to know which major
* types we should cover aside from "application".
*/
if (mediaType != null) {
// Ok: there are also "xxx+smile" subtypes, which count as well
String subtype = mediaType.getSubtype();
return CBORMediaTypes.APPLICATION_JACKSON_CBOR_TYPE.getSubtype().equalsIgnoreCase(subtype) ||
"cbor".equalsIgnoreCase(subtype) || subtype.endsWith("+cbor");
}
/* Not sure if this can happen; but it seems reasonable
* that we can at least produce smile without media type?
*/
return true;
}
/**
* Method called to locate {@link ObjectMapper} to use for serialization
* and deserialization. If an instance has been explicitly defined by
* {@link #setMapper} (or non-null instance passed in constructor), that
* will be used.
* If not, will try to locate it using standard JAX-RS
* {@link ContextResolver} mechanism, if it has been properly configured
* to access it (by JAX-RS runtime).
* Finally, if no mapper is found, will return a default unconfigured
* {@link ObjectMapper} instance (one constructed with default constructor
* and not modified in any way)
*
* @param type Class of object being serialized or deserialized;
* not checked at this point, since it is assumed that unprocessable
* classes have been already weeded out,
* but will be passed to {@link ContextResolver} as is.
* @param mediaType Declared media type for the instance to process:
* not used by this method,
* but will be passed to {@link ContextResolver} as is.
*/
@Override
protected ObjectMapper _locateMapperViaProvider(Class> type, MediaType mediaType)
{
if (_providers != null) {
ContextResolver resolver = _providers.getContextResolver(ObjectMapper.class, mediaType);
/* Above should work as is, but due to this bug
* [https://jersey.dev.java.net/issues/show_bug.cgi?id=288]
* in Jersey, it doesn't. But this works until resolution of
* the issue:
*/
if (resolver == null) {
resolver = _providers.getContextResolver(ObjectMapper.class, null);
}
if (resolver != null) {
ObjectMapper mapper = resolver.getContext(type);
// 07-Feb-2014, tatu: just in case, ensure we have correct type
if (mapper.getFactory() instanceof CBORFactory) {
return mapper;
}
}
}
return null;
}
@Override
protected CBOREndpointConfig _configForReading(ObjectReader reader,
Annotation[] annotations) {
return CBOREndpointConfig.forReading(reader, annotations);
}
@Override
protected CBOREndpointConfig _configForWriting(ObjectWriter writer,
Annotation[] annotations) {
return CBOREndpointConfig.forWriting(writer, annotations);
}
}
JacksonJaxbCBORProvider.java 0000664 0000000 0000000 00000004146 12373533575 0042131 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/fasterxml/jackson/jaxrs/cbor package com.fasterxml.jackson.jaxrs.cbor;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.ext.Provider;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
/**
* JSON content type provider automatically configured to use both Jackson
* and JAXB annotations (in that order of priority). Otherwise functionally
* same as {@link JacksonCBORProvider}.
*
* Typical usage pattern is to just instantiate instance of this
* provider for JAX-RS and use as is: this will use both Jackson and
* JAXB annotations (with Jackson annotations having priority).
*
* Note: class annotations are duplicated from super class, since it
* is not clear whether JAX-RS implementations are required to
* check settings of super-classes. It is important to keep annotations
* in sync if changed.
*/
@Provider
@Consumes(CBORMediaTypes.APPLICATION_JACKSON_CBOR)
@Produces(CBORMediaTypes.APPLICATION_JACKSON_CBOR)
public class JacksonJaxbCBORProvider extends JacksonCBORProvider {
/**
* Default annotation sets to use, if not explicitly defined during
* construction: use Jackson annotations if found; if not, use
* JAXB annotations as fallback.
*/
public final static Annotations[] DEFAULT_ANNOTATIONS = {
Annotations.JACKSON, Annotations.JAXB
};
/**
* Default constructor, usually used when provider is automatically
* configured to be used with JAX-RS implementation.
*/
public JacksonJaxbCBORProvider()
{
this(null, DEFAULT_ANNOTATIONS);
}
/**
* @param annotationsToUse Annotation set(s) to use for configuring
* data binding
*/
public JacksonJaxbCBORProvider(Annotations... annotationsToUse)
{
this(null, annotationsToUse);
}
/**
* Constructor to use when a custom mapper (usually components
* like serializer/deserializer factories that have been configured)
* is to be used.
*/
public JacksonJaxbCBORProvider(ObjectMapper mapper, Annotations[] annotationsToUse)
{
super(mapper, annotationsToUse);
}
} PackageVersion.java.in 0000664 0000000 0000000 00000001053 12373533575 0041053 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/fasterxml/jackson/jaxrs/cbor package @package@;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.core.util.VersionUtil;
/**
* Automatically generated from PackageVersion.java.in during
* packageVersion-generate execution of maven-replacer-plugin in pom.xml.
*/
public final class PackageVersion implements Versioned {
public final static Version VERSION = VersionUtil.parseVersion("@projectversion@", "@projectgroupid@", "@projectartifactid@");
@Override public Version version() { return VERSION; }
}
package-info.java 0000664 0000000 0000000 00000001455 12373533575 0040077 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/java/com/fasterxml/jackson/jaxrs/cbor /**
* Jackson-based JAX-RS provider that can automatically
* serialize and deserialize resources for
* Compact Binary Object Representation (CBOR) content type (MediaType).
*
* Also continues supporting functionality, such as
* exception mappers that can simplify handling of
* error conditions.
*
* There are two default provider classes:
*
* {@link com.fasterxml.jackson.jaxrs.xml.JacksonCBORProvider} is the basic
* provider configured to use Jackson annotations
*
* {@link com.fasterxml.jackson.jaxrs.xml.JacksonJaxbCBORProvider} is extension
* of the basic provider, configured to additionally use JAXB annotations,
* in addition to (or in addition of, if so configured) Jackson annotations.
*
*
*/
package com.fasterxml.jackson.jaxrs.cbor;
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/resources/ 0000775 0000000 0000000 00000000000 12373533575 0027564 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/resources/META-INF/ 0000775 0000000 0000000 00000000000 12373533575 0030724 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/resources/META-INF/services/ 0000775 0000000 0000000 00000000000 12373533575 0032547 5 ustar 00root root 0000000 0000000 javax.ws.rs.ext.MessageBodyReader 0000664 0000000 0000000 00000000066 12373533575 0040724 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/resources/META-INF/services com.fasterxml.jackson.jaxrs.cbor.JacksonCBORProvider
javax.ws.rs.ext.MessageBodyWriter 0000664 0000000 0000000 00000000065 12373533575 0040775 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/main/resources/META-INF/services com.fasterxml.jackson.jaxrs.cbor.JacksonCBORProvider
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/ 0000775 0000000 0000000 00000000000 12373533575 0025605 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/ 0000775 0000000 0000000 00000000000 12373533575 0026526 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/ 0000775 0000000 0000000 00000000000 12373533575 0027304 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/ 0000775 0000000 0000000 00000000000 12373533575 0031311 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/jackson/ 0000775 0000000 0000000 00000000000 12373533575 0032741 5 ustar 00root root 0000000 0000000 0000775 0000000 0000000 00000000000 12373533575 0034011 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/jackson/jaxrs 0000775 0000000 0000000 00000000000 12373533575 0034736 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/jackson/jaxrs/cbor JaxrsTestBase.java 0000664 0000000 0000000 00000006643 12373533575 0040334 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/jackson/jaxrs/cbor package com.fasterxml.jackson.jaxrs.cbor;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import org.junit.Assert;
import com.fasterxml.jackson.core.*;
public abstract class JaxrsTestBase
extends junit.framework.TestCase
{
/*
/**********************************************************
/* Additional assertion methods
/**********************************************************
*/
protected void assertToken(JsonToken expToken, JsonToken actToken)
{
if (actToken != expToken) {
fail("Expected token "+expToken+", current token "+actToken);
}
}
protected void assertToken(JsonToken expToken, JsonParser jp)
{
assertToken(expToken, jp.getCurrentToken());
}
protected void assertType(Object ob, Class> expType)
{
if (ob == null) {
fail("Expected an object of type "+expType.getName()+", got null");
}
Class> cls = ob.getClass();
if (!expType.isAssignableFrom(cls)) {
fail("Expected type "+expType.getName()+", got "+cls.getName());
}
}
protected void verifyException(Throwable e, String... matches)
{
String msg = e.getMessage();
String lmsg = (msg == null) ? "" : msg.toLowerCase();
for (String match : matches) {
String lmatch = match.toLowerCase();
if (lmsg.indexOf(lmatch) >= 0) {
return;
}
}
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
}
protected void _verifyBytes(byte[] actBytes, byte... expBytes)
{
Assert.assertArrayEquals(expBytes, actBytes);
}
/**
* Method that gets textual contents of the current token using
* available methods, and ensures results are consistent, before
* returning them
*/
protected String getAndVerifyText(JsonParser jp)
throws IOException, JsonParseException
{
// Ok, let's verify other accessors
int actLen = jp.getTextLength();
char[] ch = jp.getTextCharacters();
String str2 = new String(ch, jp.getTextOffset(), actLen);
String str = jp.getText();
if (str.length() != actLen) {
fail("Internal problem (jp.token == "+jp.getCurrentToken()+"): jp.getText().length() ['"+str+"'] == "+str.length()+"; jp.getTextLength() == "+actLen);
}
assertEquals("String access via getText(), getTextXxx() must be the same", str, str2);
return str;
}
/*
/**********************************************************
/* Other helper methods
/**********************************************************
*/
public String quote(String str) {
return '"'+str+'"';
}
protected String aposToQuotes(String json) {
return json.replace("'", "\"");
}
protected String readUTF8(InputStream in) throws IOException
{
return new String(readAll(in), "UTF-8");
}
protected byte[] readAll(InputStream in) throws IOException
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
byte[] buffer = new byte[500];
int count;
while ((count = in.read(buffer)) > 0) {
bytes.write(buffer, 0, count);
}
in.close();
return bytes.toByteArray();
}
}
TestCBORVersions.java 0000664 0000000 0000000 00000001421 12373533575 0040715 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/jackson/jaxrs/cbor package com.fasterxml.jackson.jaxrs.cbor;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
public class TestCBORVersions extends JaxrsTestBase
{
public void testMapperVersions()
{
assertVersion(new JacksonCBORProvider());
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
private void assertVersion(Versioned vers)
{
final Version v = vers.version();
assertFalse("Should find version information (got "+v+")", v.isUknownVersion());
Version exp = PackageVersion.VERSION;
assertEquals(exp.toFullString(), v.toFullString());
assertEquals(exp, v);
}
}
TestCanDeserialize.java 0000664 0000000 0000000 00000001235 12373533575 0041324 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/jackson/jaxrs/cbor package com.fasterxml.jackson.jaxrs.cbor;
import java.io.*;
import java.lang.annotation.Annotation;
import javax.ws.rs.core.MediaType;
/**
* Unit test to check [JACKSON-540]
*/
public class TestCanDeserialize extends JaxrsTestBase
{
static class Bean {
public int x;
}
// [Issue#1]: exception for no content
public void testCanSerializeEmpty() throws IOException
{
JacksonCBORProvider prov = new JacksonCBORProvider();
Bean b = (Bean) prov.readFrom(Object.class, Bean.class, new Annotation[0],
MediaType.APPLICATION_XML_TYPE, null, new ByteArrayInputStream(new byte[0]));
assertNull(b);
}
}
0000775 0000000 0000000 00000000000 12373533575 0035350 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/jackson/jaxrs/cbor/dw ResourceTestBase.java 0000664 0000000 0000000 00000006052 12373533575 0041440 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/jackson/jaxrs/cbor/dw package com.fasterxml.jackson.jaxrs.cbor.dw;
import java.util.HashSet;
import java.util.Set;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.ws.rs.core.Application;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import com.fasterxml.jackson.jaxrs.cbor.JacksonCBORProvider;
import com.fasterxml.jackson.jaxrs.cbor.JaxrsTestBase;
/**
* Intermediate base for tests that run actual full JAX-RS resource.
*/
public abstract class ResourceTestBase extends JaxrsTestBase
{
protected static abstract class CBORApplication extends Application
{
protected final Object _provider;
protected final Object _resource;
protected CBORApplication(Object provider, Object resource) {
_provider = provider;
_resource = resource;
}
@Override
public Set getSingletons() {
HashSet singletons = new HashSet();
singletons.add(_provider);
singletons.add(_resource);
return singletons;
}
}
protected static abstract class CBORApplicationWithJackson extends CBORApplication
{
public CBORApplicationWithJackson(Object resource) {
super(new JacksonCBORProvider(), resource);
}
}
/*
/**********************************************************
/* Abstract and overridable config methods
/**********************************************************
*/
protected abstract Class extends Servlet> servletContainerClass();
/*
/**********************************************************
/* Starting actual JAX-RS container
/**********************************************************
*/
protected Server startServer(int port, Class extends Application> appClass) {
return startServer(port, appClass, null);
}
protected Server startServer(int port, Class extends Application> appClass,
Class extends Filter> filterClass)
{
Server server = new Server(port);
final ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
ServletHolder jaxrs = new ServletHolder(servletContainerClass());
jaxrs.setInitParameter("javax.ws.rs.Application", appClass.getName());
final ServletContextHandler mainHandler = new ServletContextHandler(contexts, "/", true, false);
mainHandler.addServlet(jaxrs, "/*");
if (filterClass != null) {
mainHandler.addFilter(filterClass, "/*", java.util.EnumSet.allOf(DispatcherType.class));
}
server.setHandler(mainHandler);
try {
server.start();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return server;
}
}
SimpleEndpointTestBase.java 0000664 0000000 0000000 00000005364 12373533575 0042610 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/jackson/jaxrs/cbor/dw package com.fasterxml.jackson.jaxrs.cbor.dw;
import java.io.*;
import java.net.*;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.eclipse.jetty.server.Server;
import org.junit.Assert;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import com.fasterxml.jackson.jaxrs.cbor.CBORMediaTypes;
public abstract class SimpleEndpointTestBase extends ResourceTestBase
{
final static int TEST_PORT = 6011;
static class Point {
public int x, y;
protected Point() { }
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
@Path("/point")
public static class SimpleResource
{
@GET
@Produces({ CBORMediaTypes.APPLICATION_JACKSON_CBOR })
public Point getPoint() {
return new Point(1, 2);
}
}
public static class SimpleResourceApp extends CBORApplicationWithJackson {
public SimpleResourceApp() { super(new SimpleResource()); }
}
private final static byte[] UNTOUCHABLE_RESPONSE = new byte[] { 1, 2, 3, 4 };
@Path("/raw")
public static class RawResource
{
@GET
@Path("bytes")
@Produces({ CBORMediaTypes.APPLICATION_JACKSON_CBOR })
public byte[] getBytes() throws IOException {
return UNTOUCHABLE_RESPONSE;
}
}
public static class SimpleRawApp extends CBORApplicationWithJackson {
public SimpleRawApp() { super(new RawResource()); }
}
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
public void testSimpleObject() throws Exception
{
final ObjectMapper mapper = new ObjectMapper(new CBORFactory());
Server server = startServer(TEST_PORT, SimpleResourceApp.class);
Point p;
try {
InputStream in = new URL("http://localhost:"+TEST_PORT+"/point").openStream();
p = mapper.readValue(in, Point.class);
in.close();
} finally {
server.stop();
}
// ensure we got a valid Point
assertNotNull(p);
assertEquals(1, p.x);
assertEquals(2, p.y);
}
// [Issue#34] Verify that Untouchables act the way as they should
@SuppressWarnings("resource")
public void testUntouchables() throws Exception
{
Server server = startServer(TEST_PORT, SimpleRawApp.class);
try {
InputStream in = new URL("http://localhost:"+TEST_PORT+"/raw/bytes").openStream();
Assert.assertArrayEquals(UNTOUCHABLE_RESPONSE, readAll(in));
} finally {
server.stop();
}
}
}
0000775 0000000 0000000 00000000000 12373533575 0036237 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/jackson/jaxrs/cbor/jersey SimpleEndpointTest.java 0000664 0000000 0000000 00000000606 12373533575 0042676 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/cbor/src/test/java/com/fasterxml/jackson/jaxrs/cbor/jersey package com.fasterxml.jackson.jaxrs.cbor.jersey;
import javax.servlet.Servlet;
import com.fasterxml.jackson.jaxrs.cbor.dw.SimpleEndpointTestBase;
import com.sun.jersey.spi.container.servlet.ServletContainer;
public class SimpleEndpointTest extends SimpleEndpointTestBase {
@Override
protected Class extends Servlet> servletContainerClass() { return ServletContainer.class; }
}
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/ 0000775 0000000 0000000 00000000000 12373533575 0024063 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/pom.xml 0000664 0000000 0000000 00000006551 12373533575 0025407 0 ustar 00root root 0000000 0000000
4.0.0
com.fasterxml.jackson.jaxrs
jackson-jaxrs-providers
2.4.2
jackson-jaxrs-json-provider
Jackson-JAXRS-JSON
bundle
Functionality to handle JSON input/output for JAX-RS implementations (like Jersey and RESTeasy) using standard Jackson data binding.
com/fasterxml/jackson/jaxrs/json
${project.groupId}.json
${project.groupId}.json.*;version=${project.version}
javax.ws.rs;version="${javax.ws.rs.version}"
,javax.ws.rs.core;version="${javax.ws.rs.version}"
,javax.ws.rs.ext;version="${javax.ws.rs.version}"
,com.fasterxml.jackson.annotation
,com.fasterxml.jackson.core
,com.fasterxml.jackson.core.type
,com.fasterxml.jackson.core.util
,com.fasterxml.jackson.databind
,com.fasterxml.jackson.databind.introspect
,com.fasterxml.jackson.databind.type
,com.fasterxml.jackson.databind.util
,com.fasterxml.jackson.jaxrs.base
,com.fasterxml.jackson.jaxrs.cfg
,com.fasterxml.jackson.module.jaxb;resolution:=optional
jackson-jaxrs-base
${project.groupId}
${project.version}
com.fasterxml.jackson.core
jackson-core
${version.jackson.core}
com.fasterxml.jackson.core
jackson-databind
${version.jackson.core}
com.fasterxml.jackson.module
jackson-module-jaxb-annotations
${version.jackson.jaxb}
org.jboss.resteasy
resteasy-jackson2-provider
3.0.6.Final
test
com.google.code.maven-replacer-plugin
replacer
process-packageVersion
process-sources
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/ 0000775 0000000 0000000 00000000000 12373533575 0024652 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/ 0000775 0000000 0000000 00000000000 12373533575 0025576 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/ 0000775 0000000 0000000 00000000000 12373533575 0026517 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/ 0000775 0000000 0000000 00000000000 12373533575 0027275 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/ 0000775 0000000 0000000 00000000000 12373533575 0031302 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/ 0000775 0000000 0000000 00000000000 12373533575 0032732 5 ustar 00root root 0000000 0000000 0000775 0000000 0000000 00000000000 12373533575 0034002 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs 0000775 0000000 0000000 00000000000 12373533575 0034753 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json JacksonJaxbJsonProvider.java 0000664 0000000 0000000 00000004235 12373533575 0042364 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
/**
* JSON content type provider automatically configured to use both Jackson
* and JAXB annotations (in that order of priority). Otherwise functionally
* same as {@link JacksonJsonProvider}.
*
* Typical usage pattern is to just instantiate instance of this
* provider for JAX-RS and use as is: this will use both Jackson and
* JAXB annotations (with Jackson annotations having priority).
*
* Note: class annotations are duplicated from super class, since it
* is not clear whether JAX-RS implementations are required to
* check settings of super-classes. It is important to keep annotations
* in sync if changed.
*/
@Provider
@Consumes(MediaType.WILDCARD) // NOTE: required to support "non-standard" JSON variants
@Produces(MediaType.WILDCARD)
public class JacksonJaxbJsonProvider extends JacksonJsonProvider {
/**
* Default annotation sets to use, if not explicitly defined during
* construction: use Jackson annotations if found; if not, use
* JAXB annotations as fallback.
*/
public final static Annotations[] DEFAULT_ANNOTATIONS = {
Annotations.JACKSON, Annotations.JAXB
};
/**
* Default constructor, usually used when provider is automatically
* configured to be used with JAX-RS implementation.
*/
public JacksonJaxbJsonProvider()
{
this(null, DEFAULT_ANNOTATIONS);
}
/**
* @param annotationsToUse Annotation set(s) to use for configuring
* data binding
*/
public JacksonJaxbJsonProvider(Annotations... annotationsToUse)
{
this(null, annotationsToUse);
}
/**
* Constructor to use when a custom mapper (usually components
* like serializer/deserializer factories that have been configured)
* is to be used.
*/
public JacksonJaxbJsonProvider(ObjectMapper mapper, Annotations[] annotationsToUse)
{
super(mapper, annotationsToUse);
}
}
JacksonJsonProvider.java 0000664 0000000 0000000 00000021225 12373533575 0041555 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.lang.annotation.Annotation;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import javax.ws.rs.ext.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.jaxrs.base.ProviderBase;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
/**
* Basic implementation of JAX-RS abstractions ({@link MessageBodyReader},
* {@link MessageBodyWriter}) needed for binding
* JSON ("application/json") content to and from Java Objects ("POJO"s).
*
* Actual data binding functionality is implemented by {@link ObjectMapper}:
* mapper to use can be configured in multiple ways:
*
* By explicitly passing mapper to use in constructor
* By explictly setting mapper to use by {@link #setMapper}
* By defining JAX-RS Provider
that returns {@link ObjectMapper}s.
* By doing none of above, in which case a default mapper instance is
* constructed (and configured if configuration methods are called)
*
* The last method ("do nothing specific") is often good enough; explicit passing
* of Mapper is simple and explicit; and Provider-based method may make sense
* with Depedency Injection frameworks, or if Mapper has to be configured differently
* for different media types.
*
* Note that the default mapper instance will be automatically created if
* one of explicit configuration methods (like {@link #configure})
* is called: if so, Provider-based introspection is NOT used, but the
* resulting Mapper is used as configured.
*
* Note: version 1.3 added a sub-class ({@link JacksonJaxbJsonProvider}) which
* is configured by default to use both Jackson and JAXB annotations for configuration
* (base class when used as-is defaults to using just Jackson annotations)
*
* @author Tatu Saloranta
*/
@Provider
@Consumes(MediaType.WILDCARD) // NOTE: required to support "non-standard" JSON variants
@Produces(MediaType.WILDCARD)
public class JacksonJsonProvider
extends ProviderBase
{
public final static String MIME_JAVASCRIPT = "application/javascript";
public final static String MIME_JAVASCRIPT_MS = "application/x-javascript";
/**
* Default annotation sets to use, if not explicitly defined during
* construction: only Jackson annotations are used for the base
* class. Sub-classes can use other settings.
*/
public final static Annotations[] BASIC_ANNOTATIONS = {
Annotations.JACKSON
};
/*
/**********************************************************
/* General configuration
/**********************************************************
*/
/**
* JSONP function name to use for automatic JSONP wrapping, if any;
* if null, no JSONP wrapping is done.
* Note that this is the default value that can be overridden on
* per-endpoint basis.
*/
protected String _jsonpFunctionName;
/*
/**********************************************************
/* Context configuration
/**********************************************************
*/
/**
* Injectable context object used to locate configured
* instance of {@link ObjectMapper} to use for actual
* serialization.
*/
@Context
protected Providers _providers;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
/**
* Default constructor, usually used when provider is automatically
* configured to be used with JAX-RS implementation.
*/
public JacksonJsonProvider() {
this(null, BASIC_ANNOTATIONS);
}
/**
* @param annotationsToUse Annotation set(s) to use for configuring
* data binding
*/
public JacksonJsonProvider(Annotations... annotationsToUse) {
this(null, annotationsToUse);
}
public JacksonJsonProvider(ObjectMapper mapper) {
this(mapper, BASIC_ANNOTATIONS);
}
/**
* Constructor to use when a custom mapper (usually components
* like serializer/deserializer factories that have been configured)
* is to be used.
*
* @param annotationsToUse Sets of annotations (Jackson, JAXB) that provider should
* support
*/
public JacksonJsonProvider(ObjectMapper mapper, Annotations[] annotationsToUse) {
super(new JsonMapperConfigurator(mapper, annotationsToUse));
}
/**
* Method that will return version information stored in and read from jar
* that contains this class.
*/
@Override
public Version version() {
return PackageVersion.VERSION;
}
/*
/**********************************************************
/* JSON-specific configuration
/**********************************************************
*/
public void setJSONPFunctionName(String fname) {
_jsonpFunctionName = fname;
}
/*
/**********************************************************
/* Abstract method impls
/**********************************************************
*/
/**
* @deprecated Since 2.2 use {@link #hasMatchingMediaType(MediaType)} instead
*/
@Deprecated
protected boolean isJsonType(MediaType mediaType) {
return hasMatchingMediaType(mediaType);
}
/**
* Helper method used to check whether given media type
* is supported by this provider.
* Current implementation essentially checks to see whether
* {@link MediaType#getSubtype} returns "json" or something
* ending with "+json".
* Or "text/x-json" (since 2.3)
*
* @since 2.2
*/
@Override
protected boolean hasMatchingMediaType(MediaType mediaType)
{
/* As suggested by Stephen D, there are 2 ways to check: either
* being as inclusive as possible (if subtype is "json"), or
* exclusive (major type "application", minor type "json").
* Let's start with inclusive one, hard to know which major
* types we should cover aside from "application".
*/
if (mediaType != null) {
// Ok: there are also "xxx+json" subtypes, which count as well
String subtype = mediaType.getSubtype();
// [Issue#14]: also allow 'application/javascript'
return "json".equalsIgnoreCase(subtype) || subtype.endsWith("+json")
|| "javascript".equals(subtype)
// apparently Microsoft once again has interesting alternative types?
|| "x-javascript".equals(subtype)
|| "x-json".equals(subtype) // [Issue#40]
;
}
/* Not sure if this can happen; but it seems reasonable
* that we can at least produce JSON without media type?
*/
return true;
}
@Override
protected ObjectMapper _locateMapperViaProvider(Class> type, MediaType mediaType)
{
if (_providers != null) {
ContextResolver resolver = _providers.getContextResolver(ObjectMapper.class, mediaType);
/* Above should work as is, but due to this bug
* [https://jersey.dev.java.net/issues/show_bug.cgi?id=288]
* in Jersey, it doesn't. But this works until resolution of
* the issue:
*/
if (resolver == null) {
resolver = _providers.getContextResolver(ObjectMapper.class, null);
}
if (resolver != null) {
return resolver.getContext(type);
}
}
return null;
}
@Override
protected JsonEndpointConfig _configForReading(ObjectReader reader,
Annotation[] annotations) {
return JsonEndpointConfig.forReading(reader, annotations);
}
@Override
protected JsonEndpointConfig _configForWriting(ObjectWriter writer,
Annotation[] annotations) {
return JsonEndpointConfig.forWriting(writer, annotations,
_jsonpFunctionName);
}
/**
* @deprecated Since 2.3, use variant that takes explicit defaultView
*/
@Deprecated
@Override
protected JsonEndpointConfig _configForReading(ObjectMapper mapper, Annotation[] annotations) {
return _configForReading(mapper, annotations, _defaultReadView);
}
/**
* @deprecated Since 2.3, use variant that takes explicit defaultView
*/
@Deprecated
@Override
protected JsonEndpointConfig _configForWriting(ObjectMapper mapper, Annotation[] annotations) {
return _configForWriting(mapper, annotations, _defaultWriteView);
}
}
JsonEndpointConfig.java 0000664 0000000 0000000 00000006715 12373533575 0041367 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.lang.annotation.Annotation;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.fasterxml.jackson.databind.util.JSONWrappedObject;
import com.fasterxml.jackson.jaxrs.cfg.EndpointConfigBase;
import com.fasterxml.jackson.jaxrs.json.annotation.JSONP;
/**
* Container class for figuring out annotation-based configuration
* for JAX-RS end points.
*/
public class JsonEndpointConfig
extends EndpointConfigBase
{
// // Serialization-only config
protected JSONP.Def _jsonp;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
protected JsonEndpointConfig() { }
public static JsonEndpointConfig forReading(ObjectReader reader,
Annotation[] annotations)
{
return new JsonEndpointConfig()
.add(annotations, false)
.initReader(reader);
}
public static JsonEndpointConfig forWriting(ObjectWriter writer,
Annotation[] annotations,
String defaultJsonpMethod)
{
JsonEndpointConfig config = new JsonEndpointConfig();
if (defaultJsonpMethod != null) {
config._jsonp = new JSONP.Def(defaultJsonpMethod);
}
return config
.add(annotations, true)
.initWriter(writer)
;
}
/*
/**********************************************************
/* Abstract method impls, overrides
/**********************************************************
*/
@SuppressWarnings("deprecation")
@Override
protected void addAnnotation(Class extends Annotation> type,
Annotation annotation, boolean forWriting)
{
if (type == JSONP.class) {
if (forWriting) {
_jsonp = new JSONP.Def((JSONP) annotation);
}
} else if (type == com.fasterxml.jackson.jaxrs.json.annotation.JacksonFeatures.class) {
com.fasterxml.jackson.jaxrs.json.annotation.JacksonFeatures feats = (com.fasterxml.jackson.jaxrs.json.annotation.JacksonFeatures) annotation;
if (forWriting) {
_serEnable = nullIfEmpty(feats.serializationEnable());
_serDisable = nullIfEmpty(feats.serializationDisable());
} else {
_deserEnable = nullIfEmpty(feats.deserializationEnable());
_deserDisable = nullIfEmpty(feats.deserializationDisable());
}
} else {
super.addAnnotation(type, annotation, forWriting);
}
}
@Override
public Object modifyBeforeWrite(Object value) {
return applyJSONP(value);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
/**
* Method that will add JSONP wrapper object, if and as
* configured by collected annotations.
*/
public Object applyJSONP(Object value)
{
if (_jsonp != null) {
// full prefix+suffix?
if (_jsonp.prefix != null || _jsonp.suffix != null) {
return new JSONWrappedObject(_jsonp.prefix, _jsonp.suffix, value);
}
if (_jsonp.method != null) {
return new JSONPObject(_jsonp.method, value);
}
}
return value;
}
}
JsonMapperConfigurator.java 0000664 0000000 0000000 00000007550 12373533575 0042266 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.util.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
import com.fasterxml.jackson.jaxrs.cfg.MapperConfiguratorBase;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
/**
* Helper class used to encapsulate details of configuring an
* {@link ObjectMapper} instance to be used for data binding, as
* well as accessing it.
*/
public class JsonMapperConfigurator
extends MapperConfiguratorBase
{
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public JsonMapperConfigurator(ObjectMapper mapper, Annotations[] defAnnotations)
{
super(mapper, defAnnotations);
}
/**
* Method that locates, configures and returns {@link ObjectMapper} to use
*/
@Override
public synchronized ObjectMapper getConfiguredMapper() {
/* important: should NOT call mapper(); needs to return null
* if no instance has been passed or constructed
*/
return _mapper;
}
@Override
public synchronized ObjectMapper getDefaultMapper() {
if (_defaultMapper == null) {
_defaultMapper = new ObjectMapper();
_setAnnotations(_defaultMapper, _defaultAnnotationsToUse);
}
return _defaultMapper;
}
/*
/**********************************************************
/* Abstract method impl
/**********************************************************
*/
/**
* Helper method that will ensure that there is a configurable non-default
* mapper (constructing an instance if one didn't yet exit), and return
* that mapper.
*/
@Override
protected ObjectMapper mapper()
{
if (_mapper == null) {
_mapper = new ObjectMapper();
_setAnnotations(_mapper, _defaultAnnotationsToUse);
}
return _mapper;
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
@Override
protected AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse)
{
// Let's ensure there are no dups there first, filter out nulls
ArrayList intr = new ArrayList();
for (Annotations a : annotationsToUse) {
if (a != null) {
intr.add(_resolveIntrospector(a));
}
}
int count = intr.size();
if (count == 0) {
return AnnotationIntrospector.nopInstance();
}
AnnotationIntrospector curr = intr.get(0);
for (int i = 1, len = intr.size(); i < len; ++i) {
curr = AnnotationIntrospector.pair(curr, intr.get(i));
}
return curr;
}
protected AnnotationIntrospector _resolveIntrospector(Annotations ann)
{
switch (ann) {
case JACKSON:
return new JacksonAnnotationIntrospector();
case JAXB:
/* For this, need to use indirection just so that error occurs
* when we get here, and not when this class is being loaded
*/
try {
if (_jaxbIntrospectorClass == null) {
_jaxbIntrospectorClass = JaxbAnnotationIntrospector.class;
}
return _jaxbIntrospectorClass.newInstance();
} catch (Exception e) {
throw new IllegalStateException("Failed to instantiate JaxbAnnotationIntrospector: "+e.getMessage(), e);
}
default:
throw new IllegalStateException();
}
}
}
JsonMappingExceptionMapper.java 0000664 0000000 0000000 00000000505 12373533575 0043067 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import javax.ws.rs.ext.Provider;
/**
* @deprecated Since 2.2 use {@link com.fasterxml.jackson.jaxrs.base.JsonMappingExceptionMapper} instead.
*/
@Deprecated
@Provider
public class JsonMappingExceptionMapper extends com.fasterxml.jackson.jaxrs.base.JsonMappingExceptionMapper { }
JsonParseExceptionMapper.java 0000664 0000000 0000000 00000000465 12373533575 0042553 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import javax.ws.rs.ext.Provider;
/**
* @deprecated Use {@link com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper} instead.
*/
@Deprecated
@Provider
public class JsonParseExceptionMapper extends com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper { }
PackageVersion.java.in 0000664 0000000 0000000 00000001107 12373533575 0041123 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json package @package@;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.core.util.VersionUtil;
/**
* Automatically generated from PackageVersion.java.in during
* packageVersion-generate execution of maven-replacer-plugin in
* pom.xml.
*/
public final class PackageVersion implements Versioned {
public final static Version VERSION = VersionUtil.parseVersion(
"@projectversion@", "@projectgroupid@", "@projectartifactid@");
@Override
public Version version() {
return VERSION;
}
}
0000775 0000000 0000000 00000000000 12373533575 0037125 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json/annotation JSONP.java 0000664 0000000 0000000 00000005175 12373533575 0040671 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json/annotation package com.fasterxml.jackson.jaxrs.json.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/* Note: applicable to annotations to allow bundling (if support added
* to JAX-RS bundle itself), as well as methods to indicate that return
* type is to be wrapped.
* Other types are not allowed, since there is no current usage for those;
* input can't be wrapped (so no need for parameters); fields are not
* exposed through JAX-RS; and we do not allow 'default wrapping' for
* types.
*
* Note on properties: if either {@link #prefix()} or {@link #suffix()}
* is non-empty, they are used as literal prefix and suffix to use.
* Otherwise {@link #value()} is used as the function name, followed
* by opening parenthesis, value, and closing parenthesis.
*
* Example usage:
*
* class Wrapper {
* @JSONP("myFunc") public int value = 3;
* }
*
* would serialize as:
*
* myFunc({"value":3})
*
* whereas
*
*
* class Wrapper {
* @JSONP(prefix="call(", suffix=")+3") public int value = 1;
* }
*
* would serialize as:
*
* call({"value":1})+3
*
*/
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@com.fasterxml.jackson.annotation.JacksonAnnotation
public @interface JSONP
{
/**
* Method used for JSONP, unless {@link #prefix()} or
* {@link #suffix()} return non-empty Strings.
*/
public String value() default "";
/**
* Prefix String used for JSONP if not empty: will be included
* verbatim before JSON value.
*/
public String prefix() default "";
/**
* Suffix String used for JSONP if not empty: will be included
* verbatim after JSON value.
*/
public String suffix() default "";
/**
* Helper class for encapsulating information from {@link JSONP}
* annotation instance.
*/
public static class Def {
public final String method;
public final String prefix;
public final String suffix;
public Def(String m) {
method = m;
prefix = null;
suffix = null;
}
public Def(JSONP json) {
method = emptyAsNull(json.value());
prefix = emptyAsNull(json.prefix());
suffix = emptyAsNull(json.suffix());
}
private final static String emptyAsNull(String str) {
if (str == null || str.length() == 0) {
return null;
}
return str;
}
}
}
JacksonFeatures.java 0000664 0000000 0000000 00000002465 12373533575 0043066 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json/annotation package com.fasterxml.jackson.jaxrs.json.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
/**
* Annotation that can be used enable and/or disable various
* features for ObjectReader
s and ObjectWriter
s.
*
* @deprecated Since 2.2, use shared {@link com.fasterxml.jackson.jaxrs.annotation.JacksonFeatures} instead
*/
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@com.fasterxml.jackson.annotation.JacksonAnnotation
@Deprecated // since 2.2
public @interface JacksonFeatures
{
/**
* Deserialization features to enable.
*/
public DeserializationFeature[] deserializationEnable() default { };
/**
* Deserialization features to disable.
*/
public DeserializationFeature[] deserializationDisable() default { };
/**
* Serialization features to enable.
*/
public SerializationFeature[] serializationEnable() default { };
/**
* Serialization features to disable.
*/
public SerializationFeature[] serializationDisable() default { };
}
package-info.java 0000664 0000000 0000000 00000000455 12373533575 0042320 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json/annotation /**
* Package that contains annotations specific to JSON dataformat.
*
* NOTE: starting with version 2.2, general-purpose annotations
* will be moved to a shared package, and this package will only
* contains JSON-specific annotations.
*/
package com.fasterxml.jackson.jaxrs.json.annotation;
package-info.java 0000664 0000000 0000000 00000001410 12373533575 0040136 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/java/com/fasterxml/jackson/jaxrs/json /**
* Jackson-based JAX-RS provider that can automatically
* serialize and deserialize resources for
* JSON content type (MediaType).
*
* Also continues supporting functionality, such as
* exception mappers that can simplify handling of
* error conditions.
*
* There are two default provider classes:
*
* {@link com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider} is the basic
* provider configured to use Jackson annotations
*
* {@link com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider} is extension
* of the basic provider, configured to additionally use JAXB annotations,
* in addition to (or in addition of, if so configured) Jackson annotations.
*
*
*/
package com.fasterxml.jackson.jaxrs.json;
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/resources/ 0000775 0000000 0000000 00000000000 12373533575 0027610 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/resources/META-INF/ 0000775 0000000 0000000 00000000000 12373533575 0030750 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/resources/META-INF/LICENSE 0000664 0000000 0000000 00000000501 12373533575 0031751 0 ustar 00root root 0000000 0000000 This copy of Jackson JSON processor databind module is licensed under the
Apache (Software) License, version 2.0 ("the License").
See the License for details about distribution rights, and the
specific rights regarding derivate works.
You may obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/resources/META-INF/NOTICE 0000664 0000000 0000000 00000001471 12373533575 0031657 0 ustar 00root root 0000000 0000000 # Jackson JSON processor
Jackson is a high-performance, Free/Open Source JSON processing library.
It was originally written by Tatu Saloranta (tatu.saloranta@iki.fi), and has
been in development since 2007.
It is currently developed by a community of developers, as well as supported
commercially by FasterXML.com.
## Licensing
Jackson core and extension components may be licensed under different licenses.
To find the details that apply to this artifact see the accompanying LICENSE file.
For more information, including possible other licensing options, contact
FasterXML.com (http://fasterxml.com).
## Credits
A list of contributors may be found from CREDITS file, which is included
in some artifacts (usually source distributions); but is always available
from the source code management (SCM) system project uses.
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/resources/META-INF/services/ 0000775 0000000 0000000 00000000000 12373533575 0032573 5 ustar 00root root 0000000 0000000 javax.ws.rs.ext.MessageBodyReader 0000664 0000000 0000000 00000000065 12373533575 0040747 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/resources/META-INF/services com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
javax.ws.rs.ext.MessageBodyWriter 0000664 0000000 0000000 00000000065 12373533575 0041021 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/main/resources/META-INF/services com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/ 0000775 0000000 0000000 00000000000 12373533575 0025631 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/ 0000775 0000000 0000000 00000000000 12373533575 0026552 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/ 0000775 0000000 0000000 00000000000 12373533575 0027330 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/ 0000775 0000000 0000000 00000000000 12373533575 0031335 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/ 0000775 0000000 0000000 00000000000 12373533575 0032765 5 ustar 00root root 0000000 0000000 0000775 0000000 0000000 00000000000 12373533575 0034035 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs 0000775 0000000 0000000 00000000000 12373533575 0035006 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json JaxrsTestBase.java 0000664 0000000 0000000 00000005412 12373533575 0040375 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.io.IOException;
import java.util.*;
import org.junit.Assert;
import com.fasterxml.jackson.core.*;
public abstract class JaxrsTestBase
extends junit.framework.TestCase
{
/*
/**********************************************************
/* Additional assertion methods
/**********************************************************
*/
protected void assertToken(JsonToken expToken, JsonToken actToken)
{
if (actToken != expToken) {
fail("Expected token "+expToken+", current token "+actToken);
}
}
protected void assertToken(JsonToken expToken, JsonParser jp)
{
assertToken(expToken, jp.getCurrentToken());
}
protected void assertType(Object ob, Class> expType)
{
if (ob == null) {
fail("Expected an object of type "+expType.getName()+", got null");
}
Class> cls = ob.getClass();
if (!expType.isAssignableFrom(cls)) {
fail("Expected type "+expType.getName()+", got "+cls.getName());
}
}
protected void verifyException(Throwable e, String... matches)
{
String msg = e.getMessage();
String lmsg = (msg == null) ? "" : msg.toLowerCase();
for (String match : matches) {
String lmatch = match.toLowerCase();
if (lmsg.indexOf(lmatch) >= 0) {
return;
}
}
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
}
protected void _verifyBytes(byte[] actBytes, byte... expBytes)
{
Assert.assertArrayEquals(expBytes, actBytes);
}
/**
* Method that gets textual contents of the current token using
* available methods, and ensures results are consistent, before
* returning them
*/
protected String getAndVerifyText(JsonParser jp)
throws IOException, JsonParseException
{
// Ok, let's verify other accessors
int actLen = jp.getTextLength();
char[] ch = jp.getTextCharacters();
String str2 = new String(ch, jp.getTextOffset(), actLen);
String str = jp.getText();
if (str.length() != actLen) {
fail("Internal problem (jp.token == "+jp.getCurrentToken()+"): jp.getText().length() ['"+str+"'] == "+str.length()+"; jp.getTextLength() == "+actLen);
}
assertEquals("String access via getText(), getTextXxx() must be the same", str, str2);
return str;
}
/*
/**********************************************************
/* Other helper methods
/**********************************************************
*/
public String quote(String str) {
return '"'+str+'"';
}
}
TestCanDeserialize.java 0000664 0000000 0000000 00000005062 12373533575 0041376 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.jaxrs.cfg.JaxRSFeature;
/**
* Unit test to check [JACKSON-540]
*/
public class TestCanDeserialize extends JaxrsTestBase {
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testCanDeserialize() throws IOException {
Map object = new LinkedHashMap();
JacksonJsonProvider prov = new JacksonJsonProvider();
String json = "{\"foo\":\"bar\"}";
InputStream stream = new ByteArrayInputStream(json.getBytes());
object = (Map) prov.readFrom(Object.class, object.getClass(), new Annotation[0],
MediaType.APPLICATION_JSON_TYPE, null, stream);
assertEquals("bar", object.get("foo"));
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testCanDeserializeEmpty() throws IOException {
JacksonJsonProvider prov = new JacksonJsonProvider();
InputStream stream = new ByteArrayInputStream(new byte[0]);
Class type = _type(Map.class);
Map result = (Map) prov.readFrom(type, type, new Annotation[0],
MediaType.APPLICATION_JSON_TYPE, null, stream);
assertNull(result);
}
/**
* Unit test for verifying functioning of {@link JaxRSFeature#ALLOW_EMPTY_INPUT}.
*/
public void testFailingDeserializeEmpty() throws IOException {
JacksonJsonProvider prov = new JacksonJsonProvider();
prov.disable(JaxRSFeature.ALLOW_EMPTY_INPUT);
InputStream stream = new ByteArrayInputStream(new byte[0]);
Class type = _type(Map.class);
try {
prov.readFrom(type, type, new Annotation[0],
MediaType.APPLICATION_JSON_TYPE, null, stream);
fail("Should not succeed with passing of empty input");
} catch (IOException e) {
verifyException(e, "no content");
final String clsName = e.getClass().getName();
if ("javax.ws.rs.core.NoContentException".equals(clsName)) {
// Ideally, we'd get this
} else if (e.getClass() == IOException.class) {
// but for JAX-RS 1.x this'll do
} else {
fail("Unexpected exception type: "+clsName);
}
}
}
@SuppressWarnings("unchecked")
private Class _type(Class> cls) {
return (Class) cls;
}
}
TestCanSerialize.java 0000664 0000000 0000000 00000002375 12373533575 0041071 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.io.*;
import java.util.*;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Unit test to check [JACKSON-540]
*/
public class TestCanSerialize extends JaxrsTestBase
{
static class Simple {
protected List list;
public List getList( ) { return list; }
public void setList(List l) { list = l; }
}
public void testCanSerialize() throws IOException
{
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY);
// construct test object
List l = new ArrayList();
l.add("foo");
l.add("bar");
Simple s = new Simple();
s.setList(l);
// this is fine:
boolean can = mapper.canSerialize(Simple.class);
assertTrue(can);
// but with problem of [JACKSON-540], we get nasty surprise here...
String json = mapper.writeValueAsString(s);
Simple result = mapper.readValue(json, Simple.class);
assertNotNull(result.list);
assertEquals(2, result.list.size());
}
}
TestJSONVersions.java 0000664 0000000 0000000 00000001421 12373533575 0041011 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
public class TestJSONVersions extends JaxrsTestBase
{
public void testMapperVersions()
{
assertVersion(new JacksonJsonProvider());
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
private void assertVersion(Versioned vers)
{
final Version v = vers.version();
assertFalse("Should find version information (got "+v+")", v.isUknownVersion());
Version exp = PackageVersion.VERSION;
assertEquals(exp.toFullString(), v.toFullString());
assertEquals(exp, v);
}
}
TestJacksonFeatures.java 0000664 0000000 0000000 00000010246 12373533575 0041603 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.io.*;
import java.lang.annotation.*;
import java.lang.reflect.Method;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.jaxrs.annotation.JacksonFeatures;
/**
* Tests for [Issue-2], Addition of {@link JacksonFeatures}.
*/
public class TestJacksonFeatures extends JaxrsTestBase
{
static class Bean {
public int a = 3;
}
@JacksonFeatures(serializationEnable={ SerializationFeature.WRAP_ROOT_VALUE })
public void writeConfig() { }
@JacksonFeatures(deserializationDisable={ DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES })
public void readConfig() { }
// Also, let's check that we can bundle annotations
@JacksonAnnotationsInside
@JacksonFeatures(serializationEnable={ SerializationFeature.WRAP_ROOT_VALUE })
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface FeatureBundle { }
@FeatureBundle // should work as if all annotations from FeatureBundle were directly added
public void writeConfig2() { }
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
// [Issue-2], serialization
public void testWriteConfigs() throws Exception
{
JacksonJsonProvider prov = new JacksonJsonProvider();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Bean bean = new Bean();
Method m = getClass().getDeclaredMethod("writeConfig");
JacksonFeatures feats = m.getAnnotation(JacksonFeatures.class);
assertNotNull(feats); // just a sanity check
// when wrapping enabled, we get:
prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[] { feats },
MediaType.APPLICATION_JSON_TYPE, null, out);
assertEquals("{\"Bean\":{\"a\":3}}", out.toString("UTF-8"));
// but without, not:
out.reset();
prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[] { },
MediaType.APPLICATION_JSON_TYPE, null, out);
assertEquals("{\"a\":3}", out.toString("UTF-8"));
}
public void testWriteConfigsViaBundle() throws Exception
{
JacksonJsonProvider prov = new JacksonJsonProvider();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Bean bean = new Bean();
Method m = getClass().getDeclaredMethod("writeConfig2");
// should still enable root-wrapping
prov.writeTo(bean, bean.getClass(), bean.getClass(), m.getAnnotations(),
MediaType.APPLICATION_JSON_TYPE, null, out);
assertEquals("{\"Bean\":{\"a\":3}}", out.toString("UTF-8"));
}
// [Issue-2], deserialization
public void testReadConfigs() throws Exception
{
JacksonJsonProvider prov = new JacksonJsonProvider();
Method m = getClass().getDeclaredMethod("readConfig");
JacksonFeatures feats = m.getAnnotation(JacksonFeatures.class);
assertNotNull(feats); // just a sanity check
// ok: here let's verify that we can disable exception throwing unrecognized things
@SuppressWarnings("unchecked")
Class raw = (Class)(Class>)Bean.class;
Object ob = prov.readFrom(raw, raw,
new Annotation[] { feats },
MediaType.APPLICATION_JSON_TYPE, null,
new ByteArrayInputStream("{ \"foobar\" : 3 }".getBytes("UTF-8")));
assertNotNull(ob);
// but without setting, get the exception
try {
prov.readFrom(raw, raw,
new Annotation[] { },
MediaType.APPLICATION_JSON_TYPE, null,
new ByteArrayInputStream("{ \"foobar\" : 3 }".getBytes("UTF-8")));
fail("Should have caught an exception");
} catch (JsonMappingException e) {
verifyException(e, "Unrecognized field");
}
}
}
TestJsonView.java 0000664 0000000 0000000 00000003715 12373533575 0040263 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.io.ByteArrayOutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.annotation.JsonView;
public class TestJsonView extends JaxrsTestBase
{
static class MyView1 { }
static class MyView2 { }
static class Bean {
@JsonView(MyView1.class)
public int value1 = 1;
@JsonView(MyView2.class)
public int value2 = 2;
}
@JsonView({ MyView1.class })
public void bogus() { }
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
// [JACKSON-578]
public void testViews() throws Exception
{
JacksonJsonProvider prov = new JacksonJsonProvider();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Bean bean = new Bean();
Method m = getClass().getDeclaredMethod("bogus");
JsonView view = m.getAnnotation(JsonView.class);
assertNotNull(view); // just a sanity check
prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[] { view },
MediaType.APPLICATION_JSON_TYPE, null, out);
assertEquals("{\"value1\":1}", out.toString("UTF-8"));
}
// [Issue#24]
public void testDefaultView() throws Exception
{
JacksonJsonProvider prov = new JacksonJsonProvider();
prov.setDefaultWriteView(MyView2.class);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Bean bean = new Bean();
Method m = getClass().getDeclaredMethod("bogus");
JsonView view = m.getAnnotation(JsonView.class);
assertNotNull(view);
prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[0],
MediaType.APPLICATION_JSON_TYPE, null, out);
assertEquals("{\"value2\":2}", out.toString("UTF-8"));
}
}
TestJsonpWrapping.java 0000664 0000000 0000000 00000001763 12373533575 0041321 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.io.*;
import java.lang.annotation.Annotation;
import javax.ws.rs.core.MediaType;
public class TestJsonpWrapping
extends JaxrsTestBase
{
public void testSimple() throws Exception
{
JacksonJsonProvider prov = new JacksonJsonProvider();
Object bean = new Integer[] { 1, 2, 3 };
// First: no JSONP wrapping:
ByteArrayOutputStream out = new ByteArrayOutputStream();
prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[0], MediaType.APPLICATION_JSON_TYPE, null, out);
assertEquals("[1,2,3]", out.toString("UTF-8"));
// then with wrapping:
prov = new JacksonJsonProvider();
prov.setJSONPFunctionName("addAll");
out = new ByteArrayOutputStream();
prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[0], MediaType.APPLICATION_JSON_TYPE, null, out);
assertEquals("addAll([1,2,3])", out.toString("UTF-8"));
}
}
TestRootType.java 0000664 0000000 0000000 00000002634 12373533575 0040303 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.io.ByteArrayOutputStream;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
import com.fasterxml.jackson.core.type.TypeReference;
public class TestRootType
extends JaxrsTestBase
{
@JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT, property="type")
@JsonTypeName("bean")
static class Bean {
public int a = 3;
}
/*
/**********************************************************************
/* Test methods
/**********************************************************************
*/
public void testRootType() throws Exception
{
JacksonJsonProvider prov = new JacksonJsonProvider();
TypeReference> ref = new TypeReference>(){};
Bean bean = new Bean();
ArrayList list = new ArrayList();
list.add(bean);
ByteArrayOutputStream out = new ByteArrayOutputStream();
MediaType mt = MediaType.APPLICATION_JSON_TYPE;
prov.writeTo(list, List.class, ref.getType(), new Annotation[0], mt, null, out);
String json = out.toString("UTF-8");
assertEquals("[{\"bean\":{\"a\":3}}]", json);
}
}
TestSerializeWithoutAutoflush.java 0000664 0000000 0000000 00000003224 12373533575 0043720 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
/**
* Unit test to check that ProviderBase always writes its content, even if flush-after-write is off.
*/
public class TestSerializeWithoutAutoflush extends JaxrsTestBase
{
static class Simple {
protected List list;
public List getList( ) { return list; }
public void setList(List l) { list = l; }
}
public void testCanSerialize() throws IOException
{
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY);
mapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);
JacksonJsonProvider provider = new JacksonJsonProvider(mapper);
// construct test object
List l = new ArrayList();
l.add("foo");
l.add("bar");
Simple s = new Simple();
s.setList(l);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
provider.writeTo(s, Simple.class, Simple.class, new Annotation[0],
MediaType.APPLICATION_JSON_TYPE, null, stream);
Simple result = mapper.readValue(stream.toByteArray(), Simple.class);
assertNotNull(result.list);
assertEquals(2, result.list.size());
}
}
TestStreamingOutput.java 0000664 0000000 0000000 00000002021 12373533575 0041656 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.io.*;
import java.lang.annotation.Annotation;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;
public class TestStreamingOutput extends JaxrsTestBase
{
static class StreamingSubtype implements StreamingOutput
{
// important: this can trick "canSerialize()" to include it:
public int getFoo() { return 3; }
@Override
public void write(OutputStream out) throws IOException {
out.write("OK".getBytes("UTF-8"));
}
}
/*
/**********************************************************************
/* Test methods
/**********************************************************************
*/
public void testSimpleSubtype() throws Exception
{
JacksonJsonProvider prov = new JacksonJsonProvider();
assertFalse(prov.isWriteable(StreamingSubtype.class, StreamingSubtype.class,
new Annotation[] { }, MediaType.APPLICATION_JSON_TYPE));
}
}
TestUntouchables.java 0000664 0000000 0000000 00000010341 12373533575 0041144 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json package com.fasterxml.jackson.jaxrs.json;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.util.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;
/**
* Unit tests for verifying that certain JDK base types will be
* ignored by default Jackson JAX-RS conversion provider.
*/
public class TestUntouchables
extends JaxrsTestBase
{
/**
* Test type added for [JACKSON-460]... just to ensure that "isJsonType"
* remains overridable.
*/
public static class MyJacksonJsonProvider extends JacksonJsonProvider {
// ensure isJsonType remains "protected" � this is a compile-time check.
// Some users of JacksonJsonProvider override this method;
// changing to "private" would regress them.
@Override
protected boolean hasMatchingMediaType(MediaType mediaType) { return super.hasMatchingMediaType(mediaType); }
}
static class StreamingSubType implements StreamingOutput {
@Override
public void write(OutputStream output) { }
}
/*
/**********************************************************
/* Unit tests
/**********************************************************
*/
public void testDefaultUntouchables() throws Exception
{
JacksonJsonProvider prov = new JacksonJsonProvider();
// By default, no reason to exclude, say, this test class...
assertTrue(prov.isReadable(getClass(), getClass(),
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
assertTrue(prov.isWriteable(getClass(), getClass(),
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
// but some types should be ignored (set of ignorable may change over time tho!)
assertFalse(prov.isWriteable(StreamingOutput.class, StreamingOutput.class,
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
assertFalse(prov.isWriteable(StreamingSubType.class, StreamingSubType.class,
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
// and then on-the-fence things
assertFalse(prov.isReadable(String.class, getClass(),
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
assertFalse(prov.isReadable(byte[].class, getClass(),
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
}
public void testCustomUntouchables() throws Exception
{
JacksonJsonProvider prov = new JacksonJsonProvider();
// can mark this as ignorable...
prov.addUntouchable(getClass());
// and then it shouldn't be processable
assertFalse(prov.isReadable(getClass(), getClass(),
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
assertFalse(prov.isWriteable(getClass(), getClass(),
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
// Same for interfaces, like:
prov.addUntouchable(Collection.class);
assertFalse(prov.isReadable(ArrayList.class, ArrayList.class,
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
assertFalse(prov.isWriteable(HashSet.class, HashSet.class,
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
// But also allow removals...
prov.removeUntouchable(Collection.class);
assertTrue(prov.isReadable(ArrayList.class, ArrayList.class,
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
assertTrue(prov.isWriteable(HashSet.class, HashSet.class,
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
// which should even override default ones
assertFalse(prov.isReadable(String.class, getClass(),
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
assertFalse(prov.isWriteable(String.class, HashSet.class,
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
prov.removeUntouchable(String.class);
assertTrue(prov.isReadable(String.class, getClass(),
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
assertTrue(prov.isWriteable(String.class, HashSet.class,
new Annotation[0], MediaType.APPLICATION_JSON_TYPE));
}
}
0000775 0000000 0000000 00000000000 12373533575 0035420 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw ResourceTestBase.java 0000664 0000000 0000000 00000007526 12373533575 0041517 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw package com.fasterxml.jackson.jaxrs.json.dw;
import java.io.*;
import java.util.HashSet;
import java.util.Set;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.ws.rs.core.Application;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import com.fasterxml.jackson.jaxrs.json.JaxrsTestBase;
/**
* Intermediate base for tests that run actual full JAX-RS resource.
*/
public abstract class ResourceTestBase extends JaxrsTestBase
{
protected static abstract class JsonApplication extends Application
{
protected final Object _jsonProvider;
protected final Object _resource;
protected JsonApplication(Object jsonProvider, Object resource) {
_jsonProvider = jsonProvider;
_resource = resource;
}
@Override
public Set getSingletons() {
HashSet singletons = new HashSet();
singletons.add(_jsonProvider);
singletons.add(_resource);
return singletons;
}
}
protected static abstract class JsonApplicationWithJackson extends JsonApplication
{
public JsonApplicationWithJackson(Object resource) {
super(new JacksonJsonProvider(), resource);
}
}
/*
/**********************************************************
/* Abstract and overridable config methods
/**********************************************************
*/
protected abstract Class extends Servlet> servletContainerClass();
/*
/**********************************************************
/* Starting actual JAX-RS container
/**********************************************************
*/
protected Server startServer(int port, Class extends Application> appClass) {
return startServer(port, appClass, null);
}
protected Server startServer(int port, Class extends Application> appClass,
Class extends Filter> filterClass)
{
Server server = new Server(port);
final ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
ServletHolder jaxrs = new ServletHolder(servletContainerClass());
jaxrs.setInitParameter("javax.ws.rs.Application", appClass.getName());
final ServletContextHandler mainHandler = new ServletContextHandler(contexts, "/", true, false);
mainHandler.addServlet(jaxrs, "/*");
if (filterClass != null) {
mainHandler.addFilter(filterClass, "/*", java.util.EnumSet.allOf(DispatcherType.class));
}
server.setHandler(mainHandler);
try {
server.start();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return server;
}
/*
/**********************************************************
/* Other helper methods
/**********************************************************
*/
protected String aposToQuotes(String json) {
return json.replace("'", "\"");
}
protected String readUTF8(InputStream in) throws IOException
{
return new String(readAll(in), "UTF-8");
}
protected byte[] readAll(InputStream in) throws IOException
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
byte[] buffer = new byte[500];
int count;
while ((count = in.read(buffer)) > 0) {
bytes.write(buffer, 0, count);
}
in.close();
return bytes.toByteArray();
}
}
SimpleEndpointTestBase.java 0000664 0000000 0000000 00000012375 12373533575 0042660 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw package com.fasterxml.jackson.jaxrs.json.dw;
import java.io.*;
import java.net.*;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.eclipse.jetty.server.Server;
import org.junit.Assert;
import com.fasterxml.jackson.databind.ObjectMapper;
public abstract class SimpleEndpointTestBase extends ResourceTestBase
{
final static int TEST_PORT = 6011;
static class Point {
public int x, y;
protected Point() { }
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
@Path("/point")
public static class SimpleResource
{
@Path("/javascript")
@GET
@Produces({ MediaType.APPLICATION_JSON, "application/javascript" })
public Point getPointJS() {
return new Point(1, 2);
}
@Path("/jsonx")
@GET
@Produces({ MediaType.APPLICATION_JSON, "text/x-json" })
public Point getPointJSONX() {
return new Point(1, 2);
}
}
public static class SimpleResourceApp extends JsonApplicationWithJackson {
public SimpleResourceApp() { super(new SimpleResource()); }
}
private final static String UNTOUCHABLE_RESPONSE = "[1]";
@Path("/raw")
public static class RawResource
{
@GET
@Produces({ MediaType.APPLICATION_JSON, "application/javascript" })
@Path("string")
public String getString() {
return UNTOUCHABLE_RESPONSE;
}
@GET
@Path("bytes")
@Produces({ MediaType.APPLICATION_JSON, "application/javascript" })
public byte[] getBytes() throws IOException {
return UNTOUCHABLE_RESPONSE.getBytes("UTF-8");
}
}
public static class SimpleRawApp extends JsonApplicationWithJackson {
public SimpleRawApp() { super(new RawResource()); }
}
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
public void testStandardJson() throws Exception
{
final ObjectMapper mapper = new ObjectMapper();
Server server = startServer(TEST_PORT, SimpleResourceApp.class);
Point p;
try {
InputStream in = new URL("http://localhost:"+TEST_PORT+"/point/javascript").openStream();
p = mapper.readValue(in, Point.class);
in.close();
} finally {
server.stop();
}
// ensure we got a valid Point
assertNotNull(p);
assertEquals(1, p.x);
assertEquals(2, p.y);
}
public void testAcceptJavascriptType() throws Exception
{
final ObjectMapper mapper = new ObjectMapper();
Server server = startServer(TEST_PORT, SimpleResourceApp.class);
URL urlJS = new URL("http://localhost:"+TEST_PORT+"/point/javascript");
URL urlJsonX = new URL("http://localhost:"+TEST_PORT+"/point/jsonx");
try {
HttpURLConnection conn = (HttpURLConnection) urlJS.openConnection();
// First: verify that weird types are not supported...
conn.setRequestProperty("Accept", "foo/bar");
conn.connect();
assertEquals(HttpURLConnection.HTTP_NOT_ACCEPTABLE, conn.getResponseCode());
conn.disconnect();
// try again with somewhat non-standard, but supported JSON-like type (application/javascript)
conn = (HttpURLConnection) urlJS.openConnection();
conn.setRequestProperty("Accept", "application/javascript");
assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
InputStream in = conn.getInputStream();
Point p;
try {
p = mapper.readValue(in, Point.class);
} finally {
in.close();
}
assertNotNull(p);
assertEquals(1, p.x);
assertEquals(2, p.y);
conn.disconnect();
// [Issue#40]: another oddball type to consider
conn = (HttpURLConnection) urlJsonX.openConnection();
conn.setRequestProperty("Accept", "text/x-json");
assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
in = conn.getInputStream();
p = null;
try {
p = mapper.readValue(in, Point.class);
} finally {
in.close();
}
assertNotNull(p);
assertEquals(1, p.x);
assertEquals(2, p.y);
conn.disconnect();
} finally {
server.stop();
}
}
// [Issue#34] Verify that Untouchables act the way as they should
@SuppressWarnings("resource")
public void testUntouchables() throws Exception
{
Server server = startServer(TEST_PORT, SimpleRawApp.class);
try {
InputStream in = new URL("http://localhost:"+TEST_PORT+"/raw/string").openStream();
assertEquals(UNTOUCHABLE_RESPONSE, readUTF8(in));
in = new URL("http://localhost:"+TEST_PORT+"/raw/bytes").openStream();
Assert.assertArrayEquals(UNTOUCHABLE_RESPONSE.getBytes("UTF-8"), readAll(in));
} finally {
server.stop();
}
}
}
WriteModificationsTestBase.java 0000664 0000000 0000000 00000012406 12373533575 0043524 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw package com.fasterxml.jackson.jaxrs.json.dw;
import java.io.IOException;
import java.net.*;
import javax.servlet.*;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import org.eclipse.jetty.server.Server;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.jaxrs.cfg.EndpointConfigBase;
import com.fasterxml.jackson.jaxrs.cfg.ObjectWriterInjector;
import com.fasterxml.jackson.jaxrs.cfg.ObjectWriterModifier;
public abstract class WriteModificationsTestBase extends ResourceTestBase
{
final static int TEST_PORT = 6021;
final static int TEST_PORT2 = 6022;
static class Point {
public int x, y;
protected Point() { }
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
@Path("/point")
public static class SimpleResource
{
@GET
@Produces(MediaType.APPLICATION_JSON)
public Point getPoint() {
return new Point(1, 2);
}
}
@Path("/point")
public static class IndentingResource
{
@GET
@Produces(MediaType.APPLICATION_JSON)
public Point getPoint(@QueryParam("indent") String indent) {
if ("true".equals(indent)) {
ObjectWriterInjector.set(new IndentingModifier(true));
} else {
ObjectWriterInjector.set(new IndentingModifier(false));
}
return new Point(1, 2);
}
}
public static class SimpleResourceApp extends JsonApplicationWithJackson {
public SimpleResourceApp() { super(new SimpleResource()); }
}
public static class SimpleIndentingApp extends JsonApplicationWithJackson {
public SimpleIndentingApp() { super(new IndentingResource()); }
}
public static class IndentingModifier extends ObjectWriterModifier
{
public static boolean doIndent = false;
public final Boolean _indent;
public IndentingModifier() {
this(null);
}
public IndentingModifier(Boolean indent) {
_indent = indent;
}
@Override
public ObjectWriter modify(EndpointConfigBase> endpoint,
MultivaluedMap httpHeaders,
Object valueToWrite, ObjectWriter w, JsonGenerator g)
throws IOException
{
if (_indent != null) {
if (_indent.booleanValue()) {
g.useDefaultPrettyPrinter();
}
} else {
if (doIndent) {
g.useDefaultPrettyPrinter();
}
}
return w;
}
}
public static class InjectingFilter implements javax.servlet.Filter
{
@Override
public void init(FilterConfig filterConfig) throws ServletException { }
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException
{
ObjectWriterInjector.set(new IndentingModifier());
chain.doFilter(request, response);
}
@Override
public void destroy() { }
}
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
/**
* Test in which writer/generator modification is handled by
* changing state from Servlet Filter.
*/
public void testIndentationWithFilter() throws Exception
{
// We need a filter to inject modifier that enables
Server server = startServer(TEST_PORT, SimpleResourceApp.class,
InjectingFilter.class);
final URL url = new URL("http://localhost:"+TEST_PORT+"/point");
try {
// First, without indent:
IndentingModifier.doIndent = false;
String json = readUTF8(url.openStream());
assertEquals(aposToQuotes("{'x':1,'y':2}"), json);
// and then with indentation
IndentingModifier.doIndent = true;
json = readUTF8(url.openStream());
assertEquals(aposToQuotes("{\n 'x' : 1,\n 'y' : 2\n}"), json);
} finally {
server.stop();
}
}
/**
* Test in which output writer/generator is modified by assignment from
* resource method itself.
*/
public void testIndentationWithResource() throws Exception
{
// We need a filter to inject modifier that enables
Server server = startServer(TEST_PORT2, SimpleIndentingApp.class);
final String URL_BASE = "http://localhost:"+TEST_PORT2+"/point";
try {
// First, without indent:
String json = readUTF8(new URL(URL_BASE).openStream());
assertEquals(aposToQuotes("{'x':1,'y':2}"), json);
// and then with indentation
json = readUTF8(new URL(URL_BASE + "?indent=true").openStream());
assertEquals(aposToQuotes("{\n 'x' : 1,\n 'y' : 2\n}"), json);
} finally {
server.stop();
}
}
}
0000775 0000000 0000000 00000000000 12373533575 0036307 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json/jersey SimpleEndpointTest.java 0000664 0000000 0000000 00000000606 12373533575 0042746 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json/jersey package com.fasterxml.jackson.jaxrs.json.jersey;
import javax.servlet.Servlet;
import com.fasterxml.jackson.jaxrs.json.dw.SimpleEndpointTestBase;
import com.sun.jersey.spi.container.servlet.ServletContainer;
public class SimpleEndpointTest extends SimpleEndpointTestBase {
@Override
protected Class extends Servlet> servletContainerClass() { return ServletContainer.class; }
}
WriteModificationsTest.java 0000664 0000000 0000000 00000000622 12373533575 0043615 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json/jersey package com.fasterxml.jackson.jaxrs.json.jersey;
import javax.servlet.Servlet;
import com.fasterxml.jackson.jaxrs.json.dw.WriteModificationsTestBase;
import com.sun.jersey.spi.container.servlet.ServletContainer;
public class WriteModificationsTest extends WriteModificationsTestBase {
@Override
protected Class extends Servlet> servletContainerClass() { return ServletContainer.class; }
}
0000775 0000000 0000000 00000000000 12373533575 0036645 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json/resteasy RestEasyProviderLoadingTest.java 0000664 0000000 0000000 00000000710 12373533575 0045116 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json/resteasy package com.fasterxml.jackson.jaxrs.json.resteasy;
import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider;
import com.fasterxml.jackson.jaxrs.json.JaxrsTestBase;
public class RestEasyProviderLoadingTest extends JaxrsTestBase
{
public void testLoading() throws Exception
{
ResteasyJackson2Provider provider = new ResteasyJackson2Provider();
assertNotNull(provider); // just to avoid compiler warning
}
}
0000775 0000000 0000000 00000000000 12373533575 0035763 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json/util TestAnnotationBundleKey.java 0000664 0000000 0000000 00000003717 12373533575 0043413 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/json/src/test/java/com/fasterxml/jackson/jaxrs/json/util package com.fasterxml.jackson.jaxrs.json.util;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import com.fasterxml.jackson.jaxrs.cfg.AnnotationBundleKey;
import com.fasterxml.jackson.jaxrs.json.JaxrsTestBase;
import com.fasterxml.jackson.jaxrs.json.annotation.JSONP;
public class TestAnnotationBundleKey extends JaxrsTestBase
{
@JSONP("foo")
public void annotated1() { }
@JSONP("foo")
public void annotated2() { }
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
public void testKeys() throws Exception
{
Method m1 = getClass().getDeclaredMethod("annotated1");
Method m2 = getClass().getDeclaredMethod("annotated2");
assertNotSame(m1, m2);
Annotation[] ann1 = m1.getAnnotations();
assertEquals(1, ann1.length);
Annotation[] ann2 = m2.getAnnotations();
assertEquals(1, ann2.length);
AnnotationBundleKey key1 = new AnnotationBundleKey(ann1, Object.class);
AnnotationBundleKey key2 = new AnnotationBundleKey(ann2, Object.class);
AnnotationBundleKey key1dup = new AnnotationBundleKey(ann1, Object.class);
AnnotationBundleKey key1immutable = key1.immutableKey();
// identity checks first
assertEquals(key1, key1);
assertEquals(key2, key2);
assertEquals(key1dup, key1dup);
assertEquals(key1immutable, key1immutable);
assertEquals(key1.hashCode(), key1dup.hashCode());
// then inequality by content (even though both have 1 JSONP annotation)
assertFalse(key1.equals(key2));
assertFalse(key2.equals(key1));
// but safe copy ought to be equal
assertTrue(key1.equals(key1dup)); // from same method
assertTrue(key1dup.equals(key1));
assertTrue(key1.equals(key1immutable)); // and immutable variant
assertTrue(key1immutable.equals(key1));
}
}
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/pom.xml 0000664 0000000 0000000 00000007417 12373533575 0024440 0 ustar 00root root 0000000 0000000
4.0.0
com.fasterxml.jackson
jackson-parent
2.4
com.fasterxml.jackson.jaxrs
jackson-jaxrs-providers
Jackson JAX-RS
2.4.2
pom
Parent for Jackson JAX-RS providers
base
cbor
json
smile
xml
http://wiki.fasterxml.com/JacksonHome
scm:git:git@github.com:FasterXML/jackson-jaxrs-providers.git
scm:git:git@github.com:FasterXML/jackson-jaxrs-providers.git
http://github.com/FasterXML/jackson-jaxrs-providers
jackson-jaxrs-providers-2.4.2
UTF-8
2.4.0
2.4.2
${version.jackson.core}
${version.jackson.core}
${version.jackson.core}
${version.jackson.core}
1.17.1
8.1.10.v20130312
[1.1.1,2.1)
javax.ws.rs
jsr311-api
1.1.1
provided
org.eclipse.jetty
jetty-server
${version.jetty}
test
org.eclipse.jetty
jetty-servlet
${version.jetty}
test
com.sun.jersey
jersey-core
${version.jersey}
test
com.sun.jersey
jersey-server
${version.jersey}
test
com.sun.jersey
jersey-servlet
${version.jersey}
test
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/release-notes/ 0000775 0000000 0000000 00000000000 12373533575 0025660 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/release-notes/CREDITS 0000664 0000000 0000000 00000001402 12373533575 0026675 0 ustar 00root root 0000000 0000000 Here are people who have contributed to development Jackson JSON process
core component, version 2.x
(version numbers in brackets indicate release in which the problem was fixed)
(note: for older credits, check out release notes for 1.x versions)
Tatu Saloranta, tatu.saloranta@iki.fi: author
Bill Burke:
* Reported #11: ContextResolvers don't work for ObjectMapper due over-aggressive caching
(and provided samples that show how to fix it)
(2.2.2)
Matt Bishop:
* Reported #12: Missing OSGi imports
(2.2.2)
Michael Brackx (brackxm@github.com)
* Requested #19: Add `InputStream` as unwritable class
(2.2.3)
Dain Sundstrom:
* Suggested #6: Add `JaxRSFeature.ADD_NO_SNIFF_HEADER` to automatically add
X-Content-Type-Options header (works with IE)
(2.2.3)
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/release-notes/VERSION 0000664 0000000 0000000 00000007463 12373533575 0026742 0 ustar 00root root 0000000 0000000 Project: jackson-jaxrs-providers
Sub-modules:
jackson-jaxrs-cbor-provider
jackson-jaxrs-json-provider
jackson-jaxrs-smile-provider
jackson-jaxrs-xml-provider
2.4.2 (15-Aug-2014)
No changes since 2.4.0.
------------------------------------------------------------------------
=== History: ===
------------------------------------------------------------------------
2.4.1 (17-Jun-2014)
No changes since 2.4.0.
2.4.0 (02-Jun-2014)
#49: Add `JaxRSFeature.ALLOW_EMPTY_INPUT`, disabling of which can prevent
mapping of empty input into Java null value
2.3.3 (14-Apr-2014)
#41: Try to resolve problems with RESTeasy, missing `_configForWriting`
override.
(reported by `tbroyer@github`)
2.3.2 (01-Mar-2014)
#40: Allow use of "text/x-json" content type by default
(requested by kdeenanauth@github)
#42: Add CBOR provider (using jackson-dataformat-cbor)
#43: Verify that format-specific mappers are properly overridden
(like `XmlMapper` for xml)
2.3.1 (28-Dec-2013)
#37: Enable use of JAX-RS 2.0 API
(contributed by larsp@github)
2.3.0 (14-Nov-2013)
#24: Allow defining default view to use for endpoints without View annotation
#33: Provide a way to customize `ObjectReader` / `ObjectWriter` used by end points
2.2.3 (24-Aug-2013)
#6: Add `JaxRSFeature.ADD_NO_SNIFF_HEADER` to automatically add X-Content-Type-Options
header (works with IE)
(suggested by Dain S)
#12, #16: More OSGi manifest fixes
(reported by 'logoff@github')
#18: Add LICENSE, NOTICE files in artifacts
#19: Add `InputStream` as unwritable class
(requested by Michael B)
#26: Missing OSGi import for base, (c.f.j.databind.cfg)
(reported by jerome-leclercq@github)
2.2.2 (31-May-2013)
#11: ContextResolvers don't work for ObjectMapper due over-aggressive caching
(reported by Bill Burke (from Resteasy))
(PARTIAL) #12: OSGi imports missing dependency from json/smile/xml to base package
(reported by Matt Bishop)
#14: Allow "application/javascript" type for JSON provider
(requested by Stephan202@github)
2.2.1 (03-May-2013)
#8: ProviderBase does not close `JsonGenerator`
(contributed by Steven S)
#9: Dependency to Jetty was accidentally left as compile-time; should be
'test'
(reported by KlausBrunner@github)
#10: Problems with proxying of `ProviderBase` (add no-arg constructor)
2.2.0 (22-Apr-2013)
Changes:
#1: Allow binding input to `JsonParser`
#5: Add 'provider.removeUntouchable()'
* Add Woodstox dependency (not just in 'test' scope) to try to avoid problems
with users relying on SJSXP (such as 'extra' xmlns declarations)
#8: Ensure that `JsonGenerator` is always properly closed, including error cases,
otherwise can hide problems (due to missing flush of content)
(contributed by Steven S)
2.1.2 (05-Dec-2012)
No changes.
2.1.1 (11-Nov-2012)
JSON
* [Issue#17]: Accept empty content as 'null', instead of throwing an
EOFException
(requested by Matt B, cjellick@github)
2.1.0 (08-Oct-2012)
XML
* [Issue#4] Exception on empty content, should return null.
2.0.2 (14-May-2012)
JSON:
* [Issue-11] Change JAXB annotation module dependency to optional for OSGi
* [Issue-12] Revert untouchable change to 1.x compatible; so that
'String' and 'byte[]' are again "untouchable" (JSON provider will NOT
try to convert them)
2.0.1 (23-Apr-2012)
General:
* Changed 'jaxrs-311' dependency from 'compile' to 'provided'
JSON:
* SPI (META-INF/services/) fixed so auto-registration should now work
(contributed by Simone T)
* Issue-10: NPE in EndpointConfig, if JAX-RS container passes null
set of Annotations to writeTo()
2.0.0 (25-Mar-2012)
JSON:
* [Issue-1] Add @JSONP annotation for declarative JSONP support
* [Issue-2] Add @JacksonFeatures annotation for reconfiguring serialization,
deserialization features on per-endpoint basis
[entries for versions 1.x and earlier not retained; refer to earlier releases)
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/ 0000775 0000000 0000000 00000000000 12373533575 0024223 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/pom.xml 0000664 0000000 0000000 00000006371 12373533575 0025547 0 ustar 00root root 0000000 0000000
4.0.0
com.fasterxml.jackson.jaxrs
jackson-jaxrs-providers
2.4.2
jackson-jaxrs-smile-provider
Jackson-JAXRS-Smile
bundle
Functionality to handle Smile (binary JSON) input/output for JAX-RS implementations (like Jersey and RESTeasy) using standard Jackson data binding.
com/fasterxml/jackson/jaxrs/smile
${project.groupId}.smile
${project.groupId}.smile.*;version=${project.version}
javax.ws.rs
,javax.ws.rs.core
,javax.ws.rs.ext
,com.fasterxml.jackson.annotation
,com.fasterxml.jackson.core
,com.fasterxml.jackson.core.type
,com.fasterxml.jackson.core.util
,com.fasterxml.jackson.databind
,com.fasterxml.jackson.databind.introspect
,com.fasterxml.jackson.databind.type
,com.fasterxml.jackson.databind.util
,com.fasterxml.jackson.dataformat.smile
,com.fasterxml.jackson.jaxrs.base
,com.fasterxml.jackson.jaxrs.cfg
,com.fasterxml.jackson.module.jaxb;resolution:=optional
jackson-jaxrs-base
${project.groupId}
${project.version}
com.fasterxml.jackson.core
jackson-core
${version.jackson.core}
com.fasterxml.jackson.core
jackson-databind
${version.jackson.core}
com.fasterxml.jackson.dataformat
jackson-dataformat-smile
${version.jackson.smile}
com.fasterxml.jackson.module
jackson-module-jaxb-annotations
${version.jackson.jaxb}
com.google.code.maven-replacer-plugin
replacer
process-packageVersion
process-sources
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/ 0000775 0000000 0000000 00000000000 12373533575 0025012 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/ 0000775 0000000 0000000 00000000000 12373533575 0025736 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/ 0000775 0000000 0000000 00000000000 12373533575 0026657 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/ 0000775 0000000 0000000 00000000000 12373533575 0027435 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/ 0000775 0000000 0000000 00000000000 12373533575 0031442 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/ 0000775 0000000 0000000 00000000000 12373533575 0033072 5 ustar 00root root 0000000 0000000 0000775 0000000 0000000 00000000000 12373533575 0034142 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs 0000775 0000000 0000000 00000000000 12373533575 0035253 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile JacksonJaxbSmileProvider.java 0000664 0000000 0000000 00000004161 12373533575 0043022 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile package com.fasterxml.jackson.jaxrs.smile;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.ext.Provider;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
/**
* JSON content type provider automatically configured to use both Jackson
* and JAXB annotations (in that order of priority). Otherwise functionally
* same as {@link JacksonSmileProvider}.
*
* Typical usage pattern is to just instantiate instance of this
* provider for JAX-RS and use as is: this will use both Jackson and
* JAXB annotations (with Jackson annotations having priority).
*
* Note: class annotations are duplicated from super class, since it
* is not clear whether JAX-RS implementations are required to
* check settings of super-classes. It is important to keep annotations
* in sync if changed.
*/
@Provider
@Consumes(SmileMediaTypes.APPLICATION_JACKSON_SMILE)
@Produces(SmileMediaTypes.APPLICATION_JACKSON_SMILE)
public class JacksonJaxbSmileProvider extends JacksonSmileProvider {
/**
* Default annotation sets to use, if not explicitly defined during
* construction: use Jackson annotations if found; if not, use
* JAXB annotations as fallback.
*/
public final static Annotations[] DEFAULT_ANNOTATIONS = {
Annotations.JACKSON, Annotations.JAXB
};
/**
* Default constructor, usually used when provider is automatically
* configured to be used with JAX-RS implementation.
*/
public JacksonJaxbSmileProvider()
{
this(null, DEFAULT_ANNOTATIONS);
}
/**
* @param annotationsToUse Annotation set(s) to use for configuring
* data binding
*/
public JacksonJaxbSmileProvider(Annotations... annotationsToUse)
{
this(null, annotationsToUse);
}
/**
* Constructor to use when a custom mapper (usually components
* like serializer/deserializer factories that have been configured)
* is to be used.
*/
public JacksonJaxbSmileProvider(ObjectMapper mapper, Annotations[] annotationsToUse)
{
super(mapper, annotationsToUse);
}
} JacksonSmileProvider.java 0000664 0000000 0000000 00000021466 12373533575 0042224 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile package com.fasterxml.jackson.jaxrs.smile;
import java.lang.annotation.Annotation;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import javax.ws.rs.ext.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
import com.fasterxml.jackson.jaxrs.base.ProviderBase;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
/**
* Basic implementation of JAX-RS abstractions ({@link MessageBodyReader},
* {@link MessageBodyWriter}) needed for binding
* Smile ("application/x-jackson-smile") content to and from Java Objects ("POJO"s).
*
* Actual data binding functionality is implemented by {@link ObjectMapper}:
* mapper to use can be configured in multiple ways:
*
* By explicitly passing mapper to use in constructor
* By explictly setting mapper to use by {@link #setMapper}
* By defining JAX-RS Provider
that returns {@link ObjectMapper}s.
* By doing none of above, in which case a default mapper instance is
* constructed (and configured if configuration methods are called)
*
* The last method ("do nothing specific") is often good enough; explicit passing
* of Mapper is simple and explicit; and Provider-based method may make sense
* with Depedency Injection frameworks, or if Mapper has to be configured differently
* for different media types.
*
* Note that the default mapper instance will be automatically created if
* one of explicit configuration methods (like {@link #configure})
* is called: if so, Provider-based introspection is NOT used, but the
* resulting Mapper is used as configured.
*
* Note that there is also a sub-class -- ({@link JacksonJaxbSmileProvider}) -- that
* is configured by default to use both Jackson and JAXB annotations for configuration
* (base class when used as-is defaults to using just Jackson annotations)
*
* @author Tatu Saloranta
*/
@Provider
@Consumes(SmileMediaTypes.APPLICATION_JACKSON_SMILE)
@Produces(SmileMediaTypes.APPLICATION_JACKSON_SMILE)
public class JacksonSmileProvider
extends ProviderBase
{
/**
* Default annotation sets to use, if not explicitly defined during
* construction: only Jackson annotations are used for the base
* class. Sub-classes can use other settings.
*/
public final static Annotations[] BASIC_ANNOTATIONS = {
Annotations.JACKSON
};
/*
/**********************************************************
/* Context configuration
/**********************************************************
*/
/**
* Injectable context object used to locate configured
* instance of {@link ObjectMapper} to use for actual
* serialization.
*/
@Context
protected Providers _providers;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
/**
* Default constructor, usually used when provider is automatically
* configured to be used with JAX-RS implementation.
*/
public JacksonSmileProvider() {
this(null, BASIC_ANNOTATIONS);
}
/**
* @param annotationsToUse Annotation set(s) to use for configuring
* data binding
*/
public JacksonSmileProvider(Annotations... annotationsToUse)
{
this(null, annotationsToUse);
}
public JacksonSmileProvider(ObjectMapper mapper)
{
this(mapper, BASIC_ANNOTATIONS);
}
/**
* Constructor to use when a custom mapper (usually components
* like serializer/deserializer factories that have been configured)
* is to be used.
*
* @param annotationsToUse Sets of annotations (Jackson, JAXB) that provider should
* support
*/
public JacksonSmileProvider(ObjectMapper mapper, Annotations[] annotationsToUse)
{
super(new SmileMapperConfigurator(mapper, annotationsToUse));
}
/**
* Method that will return version information stored in and read from jar
* that contains this class.
*/
@Override
public Version version() {
return PackageVersion.VERSION;
}
/*
/**********************************************************
/* Abstract method impls
/**********************************************************
*/
/**
* @deprecated Since 2.2 use {@link #hasMatchingMediaType(MediaType)} instead
*/
@Deprecated
protected boolean isSmileType(MediaType mediaType) {
return hasMatchingMediaType(mediaType);
}
/**
* Helper method used to check whether given media type
* is Smile type or sub type.
* Current implementation essentially checks to see whether
* {@link MediaType#getSubtype} returns
* "smile" or something ending with "+smile".
*/
@Override
protected boolean hasMatchingMediaType(MediaType mediaType)
{
/* As suggested by Stephen D, there are 2 ways to check: either
* being as inclusive as possible (if subtype is "smile"), or
* exclusive (major type "application", minor type "smile").
* Let's start with inclusive one, hard to know which major
* types we should cover aside from "application".
*/
if (mediaType != null) {
// Ok: there are also "xxx+smile" subtypes, which count as well
String subtype = mediaType.getSubtype();
return SmileMediaTypes.APPLICATION_JACKSON_SMILE_TYPE.getSubtype().equalsIgnoreCase(subtype) ||
"smile".equalsIgnoreCase(subtype) || subtype.endsWith("+smile");
}
/* Not sure if this can happen; but it seems reasonable
* that we can at least produce smile without media type?
*/
return true;
}
/**
* Method called to locate {@link ObjectMapper} to use for serialization
* and deserialization. If an instance has been explicitly defined by
* {@link #setMapper} (or non-null instance passed in constructor), that
* will be used.
* If not, will try to locate it using standard JAX-RS
* {@link ContextResolver} mechanism, if it has been properly configured
* to access it (by JAX-RS runtime).
* Finally, if no mapper is found, will return a default unconfigured
* {@link ObjectMapper} instance (one constructed with default constructor
* and not modified in any way)
*
* @param type Class of object being serialized or deserialized;
* not checked at this point, since it is assumed that unprocessable
* classes have been already weeded out,
* but will be passed to {@link ContextResolver} as is.
* @param mediaType Declared media type for the instance to process:
* not used by this method,
* but will be passed to {@link ContextResolver} as is.
*/
@Override
protected ObjectMapper _locateMapperViaProvider(Class> type, MediaType mediaType)
{
if (_providers != null) {
ContextResolver resolver = _providers.getContextResolver(ObjectMapper.class, mediaType);
/* Above should work as is, but due to this bug
* [https://jersey.dev.java.net/issues/show_bug.cgi?id=288]
* in Jersey, it doesn't. But this works until resolution of
* the issue:
*/
if (resolver == null) {
resolver = _providers.getContextResolver(ObjectMapper.class, null);
}
if (resolver != null) {
ObjectMapper mapper = resolver.getContext(type);
// 07-Feb-2014, tatu: just in case, ensure we have correct type
if (mapper.getFactory() instanceof SmileFactory) {
return mapper;
}
}
}
return null;
}
@Override
protected SmileEndpointConfig _configForReading(ObjectReader reader,
Annotation[] annotations) {
return SmileEndpointConfig.forReading(reader, annotations);
}
@Override
protected SmileEndpointConfig _configForWriting(ObjectWriter writer,
Annotation[] annotations) {
return SmileEndpointConfig.forWriting(writer, annotations);
}
/**
* @deprecated Since 2.3, use variant that takes explicit defaultView
*/
@Deprecated
@Override
protected SmileEndpointConfig _configForReading(ObjectMapper mapper, Annotation[] annotations) {
return _configForReading(mapper, annotations, _defaultReadView);
}
/**
* @deprecated Since 2.3, use variant that takes explicit defaultView
*/
@Deprecated
@Override
protected SmileEndpointConfig _configForWriting(ObjectMapper mapper, Annotation[] annotations) {
return _configForWriting(mapper, annotations, _defaultWriteView);
}
}
JsonMappingExceptionMapper.java 0000664 0000000 0000000 00000000506 12373533575 0043370 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile package com.fasterxml.jackson.jaxrs.smile;
import javax.ws.rs.ext.Provider;
/**
* @deprecated Since 2.2 use {@link com.fasterxml.jackson.jaxrs.base.JsonMappingExceptionMapper} instead.
*/
@Deprecated
@Provider
public class JsonMappingExceptionMapper extends com.fasterxml.jackson.jaxrs.base.JsonMappingExceptionMapper { }
JsonParseExceptionMapper.java 0000664 0000000 0000000 00000000466 12373533575 0043054 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile package com.fasterxml.jackson.jaxrs.smile;
import javax.ws.rs.ext.Provider;
/**
* @deprecated Use {@link com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper} instead.
*/
@Deprecated
@Provider
public class JsonParseExceptionMapper extends com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper { }
PackageVersion.java.in 0000664 0000000 0000000 00000001107 12373533575 0041423 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile package @package@;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.core.util.VersionUtil;
/**
* Automatically generated from PackageVersion.java.in during
* packageVersion-generate execution of maven-replacer-plugin in
* pom.xml.
*/
public final class PackageVersion implements Versioned {
public final static Version VERSION = VersionUtil.parseVersion(
"@projectversion@", "@projectgroupid@", "@projectartifactid@");
@Override
public Version version() {
return VERSION;
}
}
SmileEndpointConfig.java 0000664 0000000 0000000 00000004107 12373533575 0042020 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile package com.fasterxml.jackson.jaxrs.smile;
import java.lang.annotation.Annotation;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.jaxrs.cfg.EndpointConfigBase;
/**
* Container class for figuring out annotation-based configuration
* for JAX-RS end points.
*/
public class SmileEndpointConfig
extends EndpointConfigBase
{
/*
/**********************************************************
/* Construction
/**********************************************************
*/
protected SmileEndpointConfig() { }
public static SmileEndpointConfig forReading(ObjectReader reader,
Annotation[] annotations)
{
return new SmileEndpointConfig()
.add(annotations, false)
.initReader(reader)
;
}
public static SmileEndpointConfig forWriting(ObjectWriter writer,
Annotation[] annotations)
{
SmileEndpointConfig config = new SmileEndpointConfig();
return config
.add(annotations, true)
.initWriter(writer)
;
}
@SuppressWarnings("deprecation")
@Override
protected void addAnnotation(Class extends Annotation> type,
Annotation annotation, boolean forWriting)
{
if (type == com.fasterxml.jackson.jaxrs.smile.annotation.JacksonFeatures.class) {
com.fasterxml.jackson.jaxrs.smile.annotation.JacksonFeatures feats = (com.fasterxml.jackson.jaxrs.smile.annotation.JacksonFeatures) annotation;
if (forWriting) {
_serEnable = nullIfEmpty(feats.serializationEnable());
_serDisable = nullIfEmpty(feats.serializationDisable());
} else {
_deserEnable = nullIfEmpty(feats.deserializationEnable());
_deserDisable = nullIfEmpty(feats.deserializationDisable());
}
} else {
super.addAnnotation(type, annotation, forWriting);
}
}
@Override
public Object modifyBeforeWrite(Object value) {
// nothing to add
return value;
}
}
SmileMapperConfigurator.java 0000664 0000000 0000000 00000007443 12373533575 0042727 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile package com.fasterxml.jackson.jaxrs.smile;
import java.util.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
import com.fasterxml.jackson.jaxrs.cfg.MapperConfiguratorBase;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
/**
* Helper class used to encapsulate details of configuring an
* {@link ObjectMapper} instance to be used for data binding, as
* well as accessing it.
*/
public class SmileMapperConfigurator
extends MapperConfiguratorBase
{
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public SmileMapperConfigurator(ObjectMapper mapper, Annotations[] defAnnotations)
{
super(mapper, defAnnotations);
}
/**
* Method that locates, configures and returns {@link ObjectMapper} to use
*/
@Override
public synchronized ObjectMapper getConfiguredMapper() {
/* important: should NOT call mapper(); needs to return null
* if no instance has been passed or constructed
*/
return _mapper;
}
@Override
public synchronized ObjectMapper getDefaultMapper() {
if (_defaultMapper == null) {
_defaultMapper = new ObjectMapper(new SmileFactory());
_setAnnotations(_defaultMapper, _defaultAnnotationsToUse);
}
return _defaultMapper;
}
/*
/***********************************************************
/* Internal methods
/***********************************************************
*/
/**
* Helper method that will ensure that there is a configurable non-default
* mapper (constructing an instance if one didn't yet exit), and return
* that mapper.
*/
@Override
protected ObjectMapper mapper()
{
if (_mapper == null) {
_mapper = new ObjectMapper(new SmileFactory());
_setAnnotations(_mapper, _defaultAnnotationsToUse);
}
return _mapper;
}
@Override
protected AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse)
{
// Let's ensure there are no dups there first, filter out nulls
ArrayList intr = new ArrayList();
for (Annotations a : annotationsToUse) {
if (a != null) {
intr.add(_resolveIntrospector(a));
}
}
int count = intr.size();
if (count == 0) {
return AnnotationIntrospector.nopInstance();
}
AnnotationIntrospector curr = intr.get(0);
for (int i = 1, len = intr.size(); i < len; ++i) {
curr = AnnotationIntrospector.pair(curr, intr.get(i));
}
return curr;
}
protected AnnotationIntrospector _resolveIntrospector(Annotations ann)
{
switch (ann) {
case JACKSON:
return new JacksonAnnotationIntrospector();
case JAXB:
/* For this, need to use indirection just so that error occurs
* when we get here, and not when this class is being loaded
*/
try {
if (_jaxbIntrospectorClass == null) {
_jaxbIntrospectorClass = JaxbAnnotationIntrospector.class;
}
return _jaxbIntrospectorClass.newInstance();
} catch (Exception e) {
throw new IllegalStateException("Failed to instantiate JaxbAnnotationIntrospector: "+e.getMessage(), e);
}
default:
throw new IllegalStateException();
}
}
}
SmileMediaTypes.java 0000664 0000000 0000000 00000000477 12373533575 0041164 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile package com.fasterxml.jackson.jaxrs.smile;
import javax.ws.rs.core.MediaType;
public class SmileMediaTypes {
public static final String APPLICATION_JACKSON_SMILE = "application/x-jackson-smile";
public static final MediaType APPLICATION_JACKSON_SMILE_TYPE = MediaType.valueOf(APPLICATION_JACKSON_SMILE);
}
0000775 0000000 0000000 00000000000 12373533575 0037425 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile/annotation JacksonFeatures.java 0000664 0000000 0000000 00000002466 12373533575 0043367 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile/annotation package com.fasterxml.jackson.jaxrs.smile.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
/**
* Annotation that can be used enable and/or disable various
* features for ObjectReader
s and ObjectWriter
s.
*
* @deprecated Since 2.2, use shared {@link com.fasterxml.jackson.jaxrs.annotation.JacksonFeatures} instead
*/
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@com.fasterxml.jackson.annotation.JacksonAnnotation
@Deprecated // since 2.2
public @interface JacksonFeatures
{
/**
* Deserialization features to enable.
*/
public DeserializationFeature[] deserializationEnable() default { };
/**
* Deserialization features to disable.
*/
public DeserializationFeature[] deserializationDisable() default { };
/**
* Serialization features to enable.
*/
public SerializationFeature[] serializationEnable() default { };
/**
* Serialization features to disable.
*/
public SerializationFeature[] serializationDisable() default { };
}
package.info 0000664 0000000 0000000 00000001415 12373533575 0037524 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile /**
* Jackson-based JAX-RS provider that can automatically
* serialize and deserialize resources for
* Smile content type (MediaType).
*
* Also continues supporting functionality, such as
* exception mappers that can simplify handling of
* error conditions.
*
* There are two default provider classes:
*
* {@link com.fasterxml.jackson.jaxrs.smile.JacksonSmileProvider} is the basic
* provider configured to use Jackson annotations
*
* {@link com.fasterxml.jackson.jaxrs.smile.JacksonJaxbSmileProvider} is extension
* of the basic provider, configured to additionally use JAXB annotations,
* in addition to (or in addition of, if so configured) Jackson annotations.
*
*
*/
package com.fasterxml.jackson.jaxrs.smile; jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/resources/ 0000775 0000000 0000000 00000000000 12373533575 0027750 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/resources/META-INF/ 0000775 0000000 0000000 00000000000 12373533575 0031110 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/resources/META-INF/LICENSE 0000664 0000000 0000000 00000000501 12373533575 0032111 0 ustar 00root root 0000000 0000000 This copy of Jackson JSON processor databind module is licensed under the
Apache (Software) License, version 2.0 ("the License").
See the License for details about distribution rights, and the
specific rights regarding derivate works.
You may obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/resources/META-INF/NOTICE 0000664 0000000 0000000 00000001471 12373533575 0032017 0 ustar 00root root 0000000 0000000 # Jackson JSON processor
Jackson is a high-performance, Free/Open Source JSON processing library.
It was originally written by Tatu Saloranta (tatu.saloranta@iki.fi), and has
been in development since 2007.
It is currently developed by a community of developers, as well as supported
commercially by FasterXML.com.
## Licensing
Jackson core and extension components may be licensed under different licenses.
To find the details that apply to this artifact see the accompanying LICENSE file.
For more information, including possible other licensing options, contact
FasterXML.com (http://fasterxml.com).
## Credits
A list of contributors may be found from CREDITS file, which is included
in some artifacts (usually source distributions); but is always available
from the source code management (SCM) system project uses.
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/resources/META-INF/services/ 0000775 0000000 0000000 00000000000 12373533575 0032733 5 ustar 00root root 0000000 0000000 javax.ws.rs.ext.MessageBodyReader 0000664 0000000 0000000 00000000067 12373533575 0041111 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/resources/META-INF/services com.fasterxml.jackson.jaxrs.smile.JacksonSmileProvider
javax.ws.rs.ext.MessageBodyWriter 0000664 0000000 0000000 00000000067 12373533575 0041163 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/main/resources/META-INF/services com.fasterxml.jackson.jaxrs.smile.JacksonSmileProvider
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/ 0000775 0000000 0000000 00000000000 12373533575 0025771 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/ 0000775 0000000 0000000 00000000000 12373533575 0026712 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/ 0000775 0000000 0000000 00000000000 12373533575 0027470 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/ 0000775 0000000 0000000 00000000000 12373533575 0031475 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/jackson/ 0000775 0000000 0000000 00000000000 12373533575 0033125 5 ustar 00root root 0000000 0000000 0000775 0000000 0000000 00000000000 12373533575 0034175 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/jackson/jaxrs 0000775 0000000 0000000 00000000000 12373533575 0035306 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/jackson/jaxrs/smile JaxrsTestBase.java 0000664 0000000 0000000 00000006634 12373533575 0040704 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/jackson/jaxrs/smile package com.fasterxml.jackson.jaxrs.smile;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import org.junit.Assert;
import com.fasterxml.jackson.core.*;
public abstract class JaxrsTestBase
extends junit.framework.TestCase
{
/*
/**********************************************************
/* Additional assertion methods
/**********************************************************
*/
protected void assertToken(JsonToken expToken, JsonToken actToken)
{
if (actToken != expToken) {
fail("Expected token "+expToken+", current token "+actToken);
}
}
protected void assertToken(JsonToken expToken, JsonParser jp)
{
assertToken(expToken, jp.getCurrentToken());
}
protected void assertType(Object ob, Class> expType)
{
if (ob == null) {
fail("Expected an object of type "+expType.getName()+", got null");
}
Class> cls = ob.getClass();
if (!expType.isAssignableFrom(cls)) {
fail("Expected type "+expType.getName()+", got "+cls.getName());
}
}
protected void verifyException(Throwable e, String... matches)
{
String msg = e.getMessage();
String lmsg = (msg == null) ? "" : msg.toLowerCase();
for (String match : matches) {
String lmatch = match.toLowerCase();
if (lmsg.indexOf(lmatch) >= 0) {
return;
}
}
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
}
protected void _verifyBytes(byte[] actBytes, byte... expBytes)
{
Assert.assertArrayEquals(expBytes, actBytes);
}
/**
* Method that gets textual contents of the current token using
* available methods, and ensures results are consistent, before
* returning them
*/
protected String getAndVerifyText(JsonParser jp)
throws IOException, JsonParseException
{
// Ok, let's verify other accessors
int actLen = jp.getTextLength();
char[] ch = jp.getTextCharacters();
String str2 = new String(ch, jp.getTextOffset(), actLen);
String str = jp.getText();
if (str.length() != actLen) {
fail("Internal problem (jp.token == "+jp.getCurrentToken()+"): jp.getText().length() ['"+str+"'] == "+str.length()+"; jp.getTextLength() == "+actLen);
}
assertEquals("String access via getText(), getTextXxx() must be the same", str, str2);
return str;
}
/*
/**********************************************************
/* Other helper methods
/**********************************************************
*/
public String quote(String str) {
return '"'+str+'"';
}
protected String aposToQuotes(String json) {
return json.replace("'", "\"");
}
protected String readUTF8(InputStream in) throws IOException {
return new String(readAll(in), "UTF-8");
}
protected byte[] readAll(InputStream in) throws IOException
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
byte[] buffer = new byte[500];
int count;
while ((count = in.read(buffer)) > 0) {
bytes.write(buffer, 0, count);
}
in.close();
return bytes.toByteArray();
}
}
TestCanDeserialize.java 0000664 0000000 0000000 00000002103 12373533575 0041667 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/jackson/jaxrs/smile package com.fasterxml.jackson.jaxrs.smile;
import java.io.*;
import java.lang.annotation.Annotation;
import javax.ws.rs.core.MediaType;
/**
* Unit test to check [JACKSON-540]
*/
public class TestCanDeserialize extends JaxrsTestBase
{
static class Bean {
public int x;
}
/*
public void testCanSerialize() throws IOException
{
JacksonSmileProvider prov = new JacksonSmileProvider();
byte[] smile = ...;
Bean b = (Bean) prov.readFrom(Object.class, Bean.class, new Annotation[0],
MediaType.APPLICATION_XML_TYPE, null,
new ByteArrayInputStream(smile);
assertNotNull(b);
assertEquals(3, b.x);
}
*/
// [Issue#1]: exception for no content
public void testCanSerializeEmpty() throws IOException
{
JacksonSmileProvider prov = new JacksonSmileProvider();
Bean b = (Bean) prov.readFrom(Object.class, Bean.class, new Annotation[0],
MediaType.APPLICATION_XML_TYPE, null, new ByteArrayInputStream(new byte[0]));
assertNull(b);
}
}
TestSmileVersions.java 0000664 0000000 0000000 00000001424 12373533575 0041614 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/jackson/jaxrs/smile package com.fasterxml.jackson.jaxrs.smile;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
public class TestSmileVersions extends JaxrsTestBase
{
public void testMapperVersions()
{
assertVersion(new JacksonSmileProvider());
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
private void assertVersion(Versioned vers)
{
final Version v = vers.version();
assertFalse("Should find version information (got "+v+")", v.isUknownVersion());
Version exp = PackageVersion.VERSION;
assertEquals(exp.toFullString(), v.toFullString());
assertEquals(exp, v);
}
}
0000775 0000000 0000000 00000000000 12373533575 0035720 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/jackson/jaxrs/smile/dw ResourceTestBase.java 0000664 0000000 0000000 00000006115 12373533575 0042010 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/jackson/jaxrs/smile/dw package com.fasterxml.jackson.jaxrs.smile.dw;
import java.util.HashSet;
import java.util.Set;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.ws.rs.core.Application;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import com.fasterxml.jackson.jaxrs.smile.JacksonSmileProvider;
import com.fasterxml.jackson.jaxrs.smile.JaxrsTestBase;
/**
* Intermediate base for tests that run actual full JAX-RS resource.
*/
public abstract class ResourceTestBase extends JaxrsTestBase
{
protected static abstract class SmileApplication extends Application
{
protected final Object _smileProvider;
protected final Object _resource;
protected SmileApplication(Object smileProvider, Object resource) {
_smileProvider = smileProvider;
_resource = resource;
}
@Override
public Set getSingletons() {
HashSet singletons = new HashSet();
singletons.add(_smileProvider);
singletons.add(_resource);
return singletons;
}
}
protected static abstract class SmileApplicationWithJackson extends SmileApplication
{
public SmileApplicationWithJackson(Object resource) {
super(new JacksonSmileProvider(), resource);
}
}
/*
/**********************************************************
/* Abstract and overridable config methods
/**********************************************************
*/
protected abstract Class extends Servlet> servletContainerClass();
/*
/**********************************************************
/* Starting actual JAX-RS container
/**********************************************************
*/
protected Server startServer(int port, Class extends Application> appClass) {
return startServer(port, appClass, null);
}
protected Server startServer(int port, Class extends Application> appClass,
Class extends Filter> filterClass)
{
Server server = new Server(port);
final ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
ServletHolder jaxrs = new ServletHolder(servletContainerClass());
jaxrs.setInitParameter("javax.ws.rs.Application", appClass.getName());
final ServletContextHandler mainHandler = new ServletContextHandler(contexts, "/", true, false);
mainHandler.addServlet(jaxrs, "/*");
if (filterClass != null) {
mainHandler.addFilter(filterClass, "/*", java.util.EnumSet.allOf(DispatcherType.class));
}
server.setHandler(mainHandler);
try {
server.start();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return server;
}
}
SimpleEndpointTestBase.java 0000664 0000000 0000000 00000005311 12373533575 0043150 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/jackson/jaxrs/smile/dw package com.fasterxml.jackson.jaxrs.smile.dw;
import java.io.*;
import java.net.*;
import javax.ws.rs.*;
import org.eclipse.jetty.server.Server;
import org.junit.Assert;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
import com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes;
public abstract class SimpleEndpointTestBase extends ResourceTestBase
{
final static int TEST_PORT = 6011;
static class Point {
public int x, y;
protected Point() { }
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
@Path("/point")
public static class SimpleResource
{
@GET
@Produces({ SmileMediaTypes.APPLICATION_JACKSON_SMILE })
public Point getPoint() {
return new Point(1, 2);
}
}
public static class SimpleResourceApp extends SmileApplicationWithJackson {
public SimpleResourceApp() { super(new SimpleResource()); }
}
private final static byte[] UNTOUCHABLE_RESPONSE = new byte[] { 1, 2, 3, 4 };
@Path("/raw")
public static class RawResource
{
@GET
@Path("bytes")
@Produces({ SmileMediaTypes.APPLICATION_JACKSON_SMILE })
public byte[] getBytes() throws IOException {
return UNTOUCHABLE_RESPONSE;
}
}
public static class SimpleRawApp extends SmileApplicationWithJackson {
public SimpleRawApp() { super(new RawResource()); }
}
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
public void testStandardSmile() throws Exception
{
final ObjectMapper mapper = new ObjectMapper(new SmileFactory());
Server server = startServer(TEST_PORT, SimpleResourceApp.class);
Point p;
try {
InputStream in = new URL("http://localhost:"+TEST_PORT+"/point").openStream();
p = mapper.readValue(in, Point.class);
in.close();
} finally {
server.stop();
}
// ensure we got a valid Point
assertNotNull(p);
assertEquals(1, p.x);
assertEquals(2, p.y);
}
// [Issue#34] Verify that Untouchables act the way as they should
@SuppressWarnings("resource")
public void testUntouchables() throws Exception
{
Server server = startServer(TEST_PORT, SimpleRawApp.class);
try {
InputStream in = new URL("http://localhost:"+TEST_PORT+"/raw/bytes").openStream();
Assert.assertArrayEquals(UNTOUCHABLE_RESPONSE, readAll(in));
} finally {
server.stop();
}
}
}
0000775 0000000 0000000 00000000000 12373533575 0036607 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/jackson/jaxrs/smile/jersey SimpleEndpointTest.java 0000664 0000000 0000000 00000000610 12373533575 0043241 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/smile/src/test/java/com/fasterxml/jackson/jaxrs/smile/jersey package com.fasterxml.jackson.jaxrs.smile.jersey;
import javax.servlet.Servlet;
import com.fasterxml.jackson.jaxrs.smile.dw.SimpleEndpointTestBase;
import com.sun.jersey.spi.container.servlet.ServletContainer;
public class SimpleEndpointTest extends SimpleEndpointTestBase {
@Override
protected Class extends Servlet> servletContainerClass() { return ServletContainer.class; }
}
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/ 0000775 0000000 0000000 00000000000 12373533575 0023712 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/pom.xml 0000664 0000000 0000000 00000007631 12373533575 0025236 0 ustar 00root root 0000000 0000000
4.0.0
com.fasterxml.jackson.jaxrs
jackson-jaxrs-providers
2.4.2
jackson-jaxrs-xml-provider
Jackson-JAXRS-XML
bundle
Functionality to handle XML input/output for JAX-RS implementations (like Jersey and RESTeasy) using standard Jackson data binding.
com/fasterxml/jackson/jaxrs/xml
${project.groupId}.xml
${project.groupId}.xml.*;version=${project.version}
javax.ws.rs
,javax.ws.rs.core
,javax.ws.rs.ext
,com.fasterxml.jackson.annotation
,com.fasterxml.jackson.core
,com.fasterxml.jackson.core.type
,com.fasterxml.jackson.core.util
,com.fasterxml.jackson.databind
,com.fasterxml.jackson.databind.introspect
,com.fasterxml.jackson.databind.type
,com.fasterxml.jackson.databind.util
,com.fasterxml.jackson.dataformat.xml
,com.fasterxml.jackson.dataformat.xml.jaxb
,com.fasterxml.jackson.jaxrs.base
,com.fasterxml.jackson.jaxrs.cfg
,com.fasterxml.jackson.module.jaxb;resolution:=optional
jackson-jaxrs-base
${project.groupId}
${project.version}
com.fasterxml.jackson.core
jackson-core
${version.jackson.core}
com.fasterxml.jackson.core
jackson-databind
${version.jackson.core}
com.fasterxml.jackson.dataformat
jackson-dataformat-xml
${version.jackson.xml}
com.fasterxml.jackson.module
jackson-module-jaxb-annotations
${version.jackson.jaxb}
org.codehaus.woodstox
stax2-api
3.1.1
org.codehaus.woodstox
woodstox-core-asl
4.4.0
com.google.code.maven-replacer-plugin
replacer
process-packageVersion
process-sources
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/ 0000775 0000000 0000000 00000000000 12373533575 0024501 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/ 0000775 0000000 0000000 00000000000 12373533575 0025425 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/ 0000775 0000000 0000000 00000000000 12373533575 0026346 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/ 0000775 0000000 0000000 00000000000 12373533575 0027124 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/ 0000775 0000000 0000000 00000000000 12373533575 0031131 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/ 0000775 0000000 0000000 00000000000 12373533575 0032561 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/0000775 0000000 0000000 00000000000 12373533575 0033710 5 ustar 00root root 0000000 0000000 0000775 0000000 0000000 00000000000 12373533575 0034431 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml JacksonJaxbXMLProvider.java 0000664 0000000 0000000 00000004226 12373533575 0041571 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
/**
* JSON content type provider automatically configured to use both Jackson
* and JAXB annotations (in that order of priority). Otherwise functionally
* same as {@link JacksonXMLProvider}.
*
* Typical usage pattern is to just instantiate instance of this
* provider for JAX-RS and use as is: this will use both Jackson and
* JAXB annotations (with Jackson annotations having priority).
*
* Note: class annotations are duplicated from super class, since it
* is not clear whether JAX-RS implementations are required to
* check settings of super-classes. It is important to keep annotations
* in sync if changed.
*/
@Provider
@Consumes({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
@Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
public class JacksonJaxbXMLProvider extends JacksonXMLProvider {
/**
* Default annotation sets to use, if not explicitly defined during
* construction: use Jackson annotations if found; if not, use
* JAXB annotations as fallback.
*/
public final static Annotations[] DEFAULT_ANNOTATIONS = {
Annotations.JACKSON, Annotations.JAXB
};
/**
* Default constructor, usually used when provider is automatically
* configured to be used with JAX-RS implementation.
*/
public JacksonJaxbXMLProvider()
{
this(null, DEFAULT_ANNOTATIONS);
}
/**
* @param annotationsToUse Annotation set(s) to use for configuring
* data binding
*/
public JacksonJaxbXMLProvider(Annotations... annotationsToUse)
{
this(null, annotationsToUse);
}
/**
* Constructor to use when a custom mapper (usually components
* like serializer/deserializer factories that have been configured)
* is to be used.
*/
public JacksonJaxbXMLProvider(XmlMapper mapper, Annotations[] annotationsToUse)
{
super(mapper, annotationsToUse);
}
}
JacksonXMLProvider.java 0000664 0000000 0000000 00000023073 12373533575 0040765 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import java.io.*;
import java.lang.annotation.Annotation;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.jaxrs.base.ProviderBase;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
/**
* Basic implementation of JAX-RS abstractions ({@link MessageBodyReader},
* {@link MessageBodyWriter}) needed for binding
* JSON ("application/json") content to and from Java Objects ("POJO"s).
*
* Actual data binding functionality is implemented by {@link ObjectMapper}:
* mapper to use can be configured in multiple ways:
*
* By explicitly passing mapper to use in constructor
* By explictly setting mapper to use by {@link #setMapper}
* By defining JAX-RS Provider
that returns {@link XmlMapper}s.
* By doing none of above, in which case a default mapper instance is
* constructed (and configured if configuration methods are called)
*
* The last method ("do nothing specific") is often good enough; explicit passing
* of Mapper is simple and explicit; and Provider-based method may make sense
* with Depedency Injection frameworks, or if Mapper has to be configured differently
* for different media types.
*
* Note that the default mapper instance will be automatically created if
* one of explicit configuration methods (like {@link #configure})
* is called: if so, Provider-based introspection is NOT used, but the
* resulting Mapper is used as configured.
*
* Note that there is also a sub-class -- ({@link JacksonJaxbXMLProvider}) -- that
* is configured by default to use both Jackson and JAXB annotations for configuration
* (base class when used as-is defaults to using just Jackson annotations)
*
* @author Tatu Saloranta
*/
@Provider
@Consumes({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
@Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
public class JacksonXMLProvider
extends ProviderBase
{
/**
* Default annotation sets to use, if not explicitly defined during
* construction: only Jackson annotations are used for the base
* class. Sub-classes can use other settings.
*/
public final static Annotations[] BASIC_ANNOTATIONS = {
Annotations.JACKSON
};
/*
/**********************************************************
/* Context configuration
/**********************************************************
*/
/**
* Injectable context object used to locate configured
* instance of {@link XmlMapper} to use for actual
* serialization.
*/
@Context
protected Providers _providers;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
/**
* Default constructor, usually used when provider is automatically
* configured to be used with JAX-RS implementation.
*/
public JacksonXMLProvider() {
this(null, BASIC_ANNOTATIONS);
}
/**
* @param annotationsToUse Annotation set(s) to use for configuring
* data binding
*/
public JacksonXMLProvider(Annotations... annotationsToUse)
{
this(null, annotationsToUse);
}
public JacksonXMLProvider(XmlMapper mapper) {
this(mapper, BASIC_ANNOTATIONS);
}
/**
* Constructor to use when a custom mapper (usually components
* like serializer/deserializer factories that have been configured)
* is to be used.
*
* @param annotationsToUse Sets of annotations (Jackson, JAXB) that provider should
* support
*/
public JacksonXMLProvider(XmlMapper mapper, Annotations[] annotationsToUse) {
super(new XMLMapperConfigurator(mapper, annotationsToUse));
}
/**
* Method that will return version information stored in and read from jar
* that contains this class.
*/
@Override
public Version version() {
return PackageVersion.VERSION;
}
/*
/**********************************************************
/* Abstract method impls
/**********************************************************
*/
@Override
protected XMLEndpointConfig _configForReading(ObjectReader reader,
Annotation[] annotations) {
return XMLEndpointConfig.forReading(reader, annotations);
}
@Override
protected XMLEndpointConfig _configForWriting(ObjectWriter writer,
Annotation[] annotations) {
return XMLEndpointConfig.forWriting(writer, annotations);
}
/**
* @deprecated Since 2.3, use variant that takes explicit defaultView
*/
@Deprecated
@Override
protected XMLEndpointConfig _configForReading(XmlMapper mapper, Annotation[] annotations) {
return _configForReading(mapper, annotations, _defaultReadView);
}
/**
* @deprecated Since 2.3, use variant that takes explicit defaultView
*/
@Deprecated
@Override
protected XMLEndpointConfig _configForWriting(XmlMapper mapper, Annotation[] annotations) {
return _configForWriting(mapper, annotations, _defaultWriteView);
}
/**
* @deprecated Since 2.2 use {@link #hasMatchingMediaType(MediaType)} instead
*/
@Deprecated
protected boolean isXMLType(MediaType mediaType) {
return hasMatchingMediaType(mediaType);
}
/**
* Helper method used to check whether given media type
* is XML type or sub type.
* Current implementation essentially checks to see whether
* {@link MediaType#getSubtype} returns "xml" or something
* ending with "+xml".
*/
@Override
protected boolean hasMatchingMediaType(MediaType mediaType)
{
/* As suggested by Stephen D, there are 2 ways to check: either
* being as inclusive as possible (if subtype is "xml"), or
* exclusive (major type "application", minor type "xml").
* Let's start with inclusive one, hard to know which major
* types we should cover aside from "application".
*/
if (mediaType != null) {
// Ok: there are also "xxx+xml" subtypes, which count as well
String subtype = mediaType.getSubtype();
return "xml".equalsIgnoreCase(subtype) || subtype.endsWith("+xml");
}
/* Not sure if this can happen; but it seems reasonable
* that we can at least produce XML without media type?
*/
return true;
}
/**
* Method called to locate {@link XmlMapper} to use for serialization
* and deserialization. If an instance has been explicitly defined by
* {@link #setMapper} (or non-null instance passed in constructor), that
* will be used.
* If not, will try to locate it using standard JAX-RS
* {@link ContextResolver} mechanism, if it has been properly configured
* to access it (by JAX-RS runtime).
* Finally, if no mapper is found, will return a default unconfigured
* {@link ObjectMapper} instance (one constructed with default constructor
* and not modified in any way)
*
* @param type Class of object being serialized or deserialized;
* not checked at this point, since it is assumed that unprocessable
* classes have been already weeded out,
* but will be passed to {@link ContextResolver} as is.
* @param mediaType Declared media type for the instance to process:
* not used by this method,
* but will be passed to {@link ContextResolver} as is.
*/
@Override
public XmlMapper _locateMapperViaProvider(Class> type, MediaType mediaType)
{
// First: were we configured with a specific instance?
XmlMapper m = _mapperConfig.getConfiguredMapper();
if (m == null) {
// If not, maybe we can get one configured via context?
if (_providers != null) {
ContextResolver resolver = _providers.getContextResolver(XmlMapper.class, mediaType);
/* Above should work as is, but due to this bug
* [https://jersey.dev.java.net/issues/show_bug.cgi?id=288]
* in Jersey, it doesn't. But this works until resolution of
* the issue:
*/
if (resolver == null) {
resolver = _providers.getContextResolver(XmlMapper.class, null);
}
if (resolver != null) {
m = resolver.getContext(type);
}
}
if (m == null) {
// If not, let's get the fallback default instance
m = _mapperConfig.getDefaultMapper();
}
}
return m;
}
/*
/**********************************************************
/* Overrides
/**********************************************************
*/
@Override
protected JsonParser _createParser(ObjectReader reader, InputStream rawStream)
throws IOException
{
// Fix for [Issue#4]: note, can not try to advance parser, XML parser complains
PushbackInputStream wrappedStream = new PushbackInputStream(rawStream);
int firstByte = wrappedStream.read();
if (firstByte == -1) {
return null;
}
wrappedStream.unread(firstByte);
return reader.getFactory().createParser(wrappedStream);
}
}
JsonMappingExceptionMapper.java 0000664 0000000 0000000 00000000504 12373533575 0042544 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import javax.ws.rs.ext.Provider;
/**
* @deprecated Since 2.2 use {@link com.fasterxml.jackson.jaxrs.base.JsonMappingExceptionMapper} instead.
*/
@Deprecated
@Provider
public class JsonMappingExceptionMapper extends com.fasterxml.jackson.jaxrs.base.JsonMappingExceptionMapper { }
JsonParseExceptionMapper.java 0000664 0000000 0000000 00000000464 12373533575 0042230 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import javax.ws.rs.ext.Provider;
/**
* @deprecated Use {@link com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper} instead.
*/
@Deprecated
@Provider
public class JsonParseExceptionMapper extends com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper { }
PackageVersion.java.in 0000664 0000000 0000000 00000001107 12373533575 0040601 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml package @package@;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.core.util.VersionUtil;
/**
* Automatically generated from PackageVersion.java.in during
* packageVersion-generate execution of maven-replacer-plugin in
* pom.xml.
*/
public final class PackageVersion implements Versioned {
public final static Version VERSION = VersionUtil.parseVersion(
"@projectversion@", "@projectgroupid@", "@projectartifactid@");
@Override
public Version version() {
return VERSION;
}
}
XMLEndpointConfig.java 0000664 0000000 0000000 00000004043 12373533575 0040564 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import java.lang.annotation.Annotation;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.jaxrs.cfg.EndpointConfigBase;
/**
* Container class for figuring out annotation-based configuration
* for JAX-RS end points.
*/
public class XMLEndpointConfig
extends EndpointConfigBase
{
/*
/**********************************************************
/* Construction
/**********************************************************
*/
protected XMLEndpointConfig() { }
public static XMLEndpointConfig forReading(ObjectReader reader,
Annotation[] annotations)
{
return new XMLEndpointConfig()
.add(annotations, false)
.initReader(reader);
}
public static XMLEndpointConfig forWriting(ObjectWriter writer,
Annotation[] annotations)
{
XMLEndpointConfig config = new XMLEndpointConfig();
return config
.add(annotations, true)
.initWriter(writer)
;
}
@SuppressWarnings("deprecation")
@Override
protected void addAnnotation(Class extends Annotation> type,
Annotation annotation, boolean forWriting)
{
if (type == com.fasterxml.jackson.jaxrs.xml.annotation.JacksonFeatures.class) {
com.fasterxml.jackson.jaxrs.xml.annotation.JacksonFeatures feats = (com.fasterxml.jackson.jaxrs.xml.annotation.JacksonFeatures) annotation;
if (forWriting) {
_serEnable = nullIfEmpty(feats.serializationEnable());
_serDisable = nullIfEmpty(feats.serializationDisable());
} else {
_deserEnable = nullIfEmpty(feats.deserializationEnable());
_deserDisable = nullIfEmpty(feats.deserializationDisable());
}
} else {
super.addAnnotation(type, annotation, forWriting);
}
}
@Override
public Object modifyBeforeWrite(Object value) {
// nothing to add
return value;
}
}
XMLMapperConfigurator.java 0000664 0000000 0000000 00000010413 12373533575 0041463 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import java.util.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlAnnotationIntrospector;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.jaxb.XmlJaxbAnnotationIntrospector;
import com.fasterxml.jackson.jaxrs.cfg.Annotations;
import com.fasterxml.jackson.jaxrs.cfg.MapperConfiguratorBase;
/**
* Helper class used to encapsulate details of configuring an
* {@link XmlMapper} instance to be used for data binding, as
* well as accessing it.
*/
public class XMLMapperConfigurator
extends MapperConfiguratorBase
{
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public XMLMapperConfigurator(XmlMapper mapper, Annotations[] defAnnotations)
{
super(mapper, defAnnotations);
}
/**
* Method that locates, configures and returns {@link XmlMapper} to use
*/
@Override
public synchronized XmlMapper getConfiguredMapper() {
/* important: should NOT call mapper(); needs to return null
* if no instance has been passed or constructed
*/
return _mapper;
}
@Override
public synchronized XmlMapper getDefaultMapper()
{
if (_defaultMapper == null) {
// 10-Oct-2012, tatu: Better do things explicitly...
JacksonXmlModule module = getConfiguredModule();
_defaultMapper = (module == null) ? new XmlMapper() : new XmlMapper(module);
_setAnnotations(_defaultMapper, _defaultAnnotationsToUse);
}
return _defaultMapper;
}
protected JacksonXmlModule getConfiguredModule()
{
return new JacksonXmlModule();
}
/*
/***********************************************************
/* Internal methods
/***********************************************************
*/
/**
* Helper method that will ensure that there is a configurable non-default
* mapper (constructing an instance if one didn't yet exit), and return
* that mapper.
*/
@Override
protected XmlMapper mapper()
{
if (_mapper == null) {
_mapper = new XmlMapper();
_setAnnotations(_mapper, _defaultAnnotationsToUse);
}
return _mapper;
}
@Override
protected AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse)
{
// Let's ensure there are no dups there first, filter out nulls
ArrayList intr = new ArrayList();
for (Annotations a : annotationsToUse) {
if (a != null) {
intr.add(_resolveIntrospector(a));
}
}
int count = intr.size();
if (count == 0) {
return AnnotationIntrospector.nopInstance();
}
AnnotationIntrospector curr = intr.get(0);
for (int i = 1, len = intr.size(); i < len; ++i) {
curr = AnnotationIntrospector.pair(curr, intr.get(i));
}
return curr;
}
protected AnnotationIntrospector _resolveIntrospector(Annotations ann)
{
/* 11-Oct-2012, tatu: IMPORTANT: we MUST override choices here,
* since XML module provides extended versions of BOTH standard
* AnnotationIntrospectors.
*/
switch (ann) {
case JACKSON:
return new JacksonXmlAnnotationIntrospector();
case JAXB:
/* For this, need to use indirection just so that error occurs
* when we get here, and not when this class is being loaded
*/
try {
if (_jaxbIntrospectorClass == null) {
_jaxbIntrospectorClass = XmlJaxbAnnotationIntrospector.class;
}
return _jaxbIntrospectorClass.newInstance();
} catch (Exception e) {
throw new IllegalStateException("Failed to instantiate XmlJaxbAnnotationIntrospector: "+e.getMessage(), e);
}
default:
throw new IllegalStateException();
}
}
}
0000775 0000000 0000000 00000000000 12373533575 0036603 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml/annotation JacksonFeatures.java 0000664 0000000 0000000 00000002464 12373533575 0042543 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml/annotation package com.fasterxml.jackson.jaxrs.xml.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
/**
* Annotation that can be used enable and/or disable various
* features for ObjectReader
s and ObjectWriter
s.
*
* @deprecated Since 2.2, use shared {@link com.fasterxml.jackson.jaxrs.annotation.JacksonFeatures} instead
*/
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@com.fasterxml.jackson.annotation.JacksonAnnotation
@Deprecated // since 2.2
public @interface JacksonFeatures
{
/**
* Deserialization features to enable.
*/
public DeserializationFeature[] deserializationEnable() default { };
/**
* Deserialization features to disable.
*/
public DeserializationFeature[] deserializationDisable() default { };
/**
* Serialization features to enable.
*/
public SerializationFeature[] serializationEnable() default { };
/**
* Serialization features to disable.
*/
public SerializationFeature[] serializationDisable() default { };
}
package-info.java 0000664 0000000 0000000 00000001402 12373533575 0037615 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml /**
* Jackson-based JAX-RS provider that can automatically
* serialize and deserialize resources for
* XML content type (MediaType).
*
* Also continues supporting functionality, such as
* exception mappers that can simplify handling of
* error conditions.
*
* There are two default provider classes:
*
* {@link com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider} is the basic
* provider configured to use Jackson annotations
*
* {@link com.fasterxml.jackson.jaxrs.xml.JacksonJaxbXMLProvider} is extension
* of the basic provider, configured to additionally use JAXB annotations,
* in addition to (or in addition of, if so configured) Jackson annotations.
*
*
*/
package com.fasterxml.jackson.jaxrs.xml;
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/resources/ 0000775 0000000 0000000 00000000000 12373533575 0027437 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/resources/META-INF/ 0000775 0000000 0000000 00000000000 12373533575 0030577 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/resources/META-INF/LICENSE 0000664 0000000 0000000 00000000501 12373533575 0031600 0 ustar 00root root 0000000 0000000 This copy of Jackson JSON processor databind module is licensed under the
Apache (Software) License, version 2.0 ("the License").
See the License for details about distribution rights, and the
specific rights regarding derivate works.
You may obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/resources/META-INF/NOTICE 0000664 0000000 0000000 00000001471 12373533575 0031506 0 ustar 00root root 0000000 0000000 # Jackson JSON processor
Jackson is a high-performance, Free/Open Source JSON processing library.
It was originally written by Tatu Saloranta (tatu.saloranta@iki.fi), and has
been in development since 2007.
It is currently developed by a community of developers, as well as supported
commercially by FasterXML.com.
## Licensing
Jackson core and extension components may be licensed under different licenses.
To find the details that apply to this artifact see the accompanying LICENSE file.
For more information, including possible other licensing options, contact
FasterXML.com (http://fasterxml.com).
## Credits
A list of contributors may be found from CREDITS file, which is included
in some artifacts (usually source distributions); but is always available
from the source code management (SCM) system project uses.
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/resources/META-INF/services/ 0000775 0000000 0000000 00000000000 12373533575 0032422 5 ustar 00root root 0000000 0000000 javax.ws.rs.ext.MessageBodyReader 0000664 0000000 0000000 00000000064 12373533575 0040575 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/resources/META-INF/services com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider
javax.ws.rs.ext.MessageBodyWriter 0000664 0000000 0000000 00000000063 12373533575 0040646 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/main/resources/META-INF/services com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider
jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/ 0000775 0000000 0000000 00000000000 12373533575 0025460 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/ 0000775 0000000 0000000 00000000000 12373533575 0026401 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/ 0000775 0000000 0000000 00000000000 12373533575 0027157 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/ 0000775 0000000 0000000 00000000000 12373533575 0031164 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/ 0000775 0000000 0000000 00000000000 12373533575 0032614 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/0000775 0000000 0000000 00000000000 12373533575 0033743 5 ustar 00root root 0000000 0000000 0000775 0000000 0000000 00000000000 12373533575 0034464 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml JaxrsTestBase.java 0000664 0000000 0000000 00000006552 12373533575 0040061 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import org.junit.Assert;
import com.fasterxml.jackson.core.*;
public abstract class JaxrsTestBase
extends junit.framework.TestCase
{
/*
/**********************************************************
/* Additional assertion methods
/**********************************************************
*/
protected void assertToken(JsonToken expToken, JsonToken actToken)
{
if (actToken != expToken) {
fail("Expected token "+expToken+", current token "+actToken);
}
}
protected void assertToken(JsonToken expToken, JsonParser jp)
{
assertToken(expToken, jp.getCurrentToken());
}
protected void assertType(Object ob, Class> expType)
{
if (ob == null) {
fail("Expected an object of type "+expType.getName()+", got null");
}
Class> cls = ob.getClass();
if (!expType.isAssignableFrom(cls)) {
fail("Expected type "+expType.getName()+", got "+cls.getName());
}
}
protected void verifyException(Throwable e, String... matches)
{
String msg = e.getMessage();
String lmsg = (msg == null) ? "" : msg.toLowerCase();
for (String match : matches) {
String lmatch = match.toLowerCase();
if (lmsg.indexOf(lmatch) >= 0) {
return;
}
}
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
}
protected void _verifyBytes(byte[] actBytes, byte... expBytes)
{
Assert.assertArrayEquals(expBytes, actBytes);
}
/**
* Method that gets textual contents of the current token using
* available methods, and ensures results are consistent, before
* returning them
*/
protected String getAndVerifyText(JsonParser jp)
throws IOException, JsonParseException
{
// Ok, let's verify other accessors
int actLen = jp.getTextLength();
char[] ch = jp.getTextCharacters();
String str2 = new String(ch, jp.getTextOffset(), actLen);
String str = jp.getText();
if (str.length() != actLen) {
fail("Internal problem (jp.token == "+jp.getCurrentToken()+"): jp.getText().length() ['"+str+"'] == "+str.length()+"; jp.getTextLength() == "+actLen);
}
assertEquals("String access via getText(), getTextXxx() must be the same", str, str2);
return str;
}
/*
/**********************************************************
/* Other helper methods
/**********************************************************
*/
public String quote(String str) {
return '"'+str+'"';
}
protected byte[] readAll(InputStream in) throws IOException
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
byte[] buffer = new byte[500];
int count;
while ((count = in.read(buffer)) > 0) {
bytes.write(buffer, 0, count);
}
in.close();
return bytes.toByteArray();
}
protected Exception unwrap(Exception e) {
while (e.getCause() instanceof Exception) {
e = (Exception) e.getCause();
}
return e;
}
}
TestCanDeserialize.java 0000664 0000000 0000000 00000002134 12373533575 0041051 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import java.io.*;
import java.lang.annotation.Annotation;
import javax.ws.rs.core.MediaType;
/**
* Unit test to check [JACKSON-540]
*/
public class TestCanDeserialize extends JaxrsTestBase
{
static class Bean {
public int x;
}
public void testCanSerialize() throws IOException
{
JacksonXMLProvider prov = new JacksonXMLProvider();
String XML = "3 ";
InputStream stream = new ByteArrayInputStream(XML.getBytes());
Bean b = (Bean) prov.readFrom(Object.class, Bean.class, new Annotation[0],
MediaType.APPLICATION_XML_TYPE, null, stream);
assertNotNull(b);
assertEquals(3, b.x);
}
// [Issue#4]: exception for no content
public void testCanSerializeEmpty() throws IOException
{
JacksonXMLProvider prov = new JacksonXMLProvider();
Bean b = (Bean) prov.readFrom(Object.class, Bean.class, new Annotation[0],
MediaType.APPLICATION_XML_TYPE, null, new ByteArrayInputStream(new byte[0]));
assertNull(b);
}
}
TestCanSerialize.java 0000664 0000000 0000000 00000002374 12373533575 0040546 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import java.io.*;
import java.util.*;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Unit test to check [JACKSON-540]
*/
public class TestCanSerialize extends JaxrsTestBase
{
static class Simple {
protected List list;
public List getList( ) { return list; }
public void setList(List l) { list = l; }
}
public void testCanSerialize() throws IOException
{
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY);
// construct test object
List l = new ArrayList();
l.add("foo");
l.add("bar");
Simple s = new Simple();
s.setList(l);
// this is fine:
boolean can = mapper.canSerialize(Simple.class);
assertTrue(can);
// but with problem of [JACKSON-540], we get nasty surprise here...
String json = mapper.writeValueAsString(s);
Simple result = mapper.readValue(json, Simple.class);
assertNotNull(result.list);
assertEquals(2, result.list.size());
}
}
TestJacksonFeaturesWithXML.java 0000664 0000000 0000000 00000011154 12373533575 0042475 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import java.io.*;
import java.lang.annotation.*;
import java.lang.reflect.Method;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.jaxrs.annotation.JacksonFeatures;
import com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider;
/**
* Tests for [Issue-2], Addition of {@link JacksonFeatures}.
*/
public class TestJacksonFeaturesWithXML extends JaxrsTestBase
{
static class Bean {
public int a = 3;
}
@JacksonFeatures(serializationEnable={ SerializationFeature.WRAP_ROOT_VALUE })
public void writeConfig() { }
@JacksonFeatures(deserializationDisable={ DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES })
public void readConfig() { }
// Also, let's check that we can bundle annotations
@JacksonAnnotationsInside
@JacksonFeatures(serializationEnable={ SerializationFeature.WRAP_ROOT_VALUE })
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface FeatureBundle { }
@FeatureBundle // should work as if all annotations from FeatureBundle were directly added
public void writeConfig2() { }
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
// [Issue-2], serialization
public void testWriteConfigs() throws Exception
{
JacksonXMLProvider prov = new JacksonXMLProvider();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Bean bean = new Bean();
Method m = getClass().getDeclaredMethod("writeConfig");
JacksonFeatures feats = m.getAnnotation(JacksonFeatures.class);
assertNotNull(feats); // just a sanity check
/* 09-Oct-2013, tatu: As of 2.3, XML backend does NOT add extra wrapping
* any more: it is only added to JSON where it is needed; but not
* to XML which always basically uses wrapping.
*/
try {
prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[] { feats },
MediaType.APPLICATION_JSON_TYPE, null, out);
} catch (Exception e) {
throw unwrap(e);
}
//
assertEquals("3 ", out.toString("UTF-8"));
// but without, not:
out.reset();
prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[] { },
MediaType.APPLICATION_JSON_TYPE, null, out);
assertEquals("3 ", out.toString("UTF-8"));
}
public void testWriteConfigsViaBundle() throws Exception
{
JacksonXMLProvider prov = new JacksonXMLProvider();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Bean bean = new Bean();
Method m = getClass().getDeclaredMethod("writeConfig2");
// should still enable root-wrapping
prov.writeTo(bean, bean.getClass(), bean.getClass(), m.getAnnotations(),
MediaType.APPLICATION_JSON_TYPE, null, out);
// as per above, no extra wrapping for XML, in 2.3:
assertEquals("3 ", out.toString("UTF-8"));
}
// [Issue-2], deserialization
public void testReadConfigs() throws Exception
{
JacksonXMLProvider prov = new JacksonXMLProvider();
Method m = getClass().getDeclaredMethod("readConfig");
JacksonFeatures feats = m.getAnnotation(JacksonFeatures.class);
assertNotNull(feats); // just a sanity check
// ok: here let's verify that we can disable exception throwing unrecognized things
@SuppressWarnings("unchecked")
Class raw = (Class)(Class>)Bean.class;
Object ob = prov.readFrom(raw, raw,
new Annotation[] { feats },
MediaType.APPLICATION_JSON_TYPE, null,
new ByteArrayInputStream("3 ".getBytes("UTF-8")));
assertNotNull(ob);
// but without setting, get the exception
try {
prov.readFrom(raw, raw,
new Annotation[] { },
MediaType.APPLICATION_JSON_TYPE, null,
new ByteArrayInputStream("3 ".getBytes("UTF-8")));
fail("Should have caught an exception");
} catch (JsonMappingException e) {
verifyException(e, "Unrecognized field");
}
}
}
TestJsonView.java 0000664 0000000 0000000 00000002630 12373533575 0037734 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import java.io.ByteArrayOutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider;
public class TestJsonView extends JaxrsTestBase
{
static class MyView1 { }
static class MyView2 { }
static class Bean {
@JsonView(MyView1.class)
public int value1 = 1;
@JsonView(MyView2.class)
public int value2 = 2;
}
@JsonView({ MyView1.class })
public void bogus() { }
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
// [JACKSON-578]
public void testViews() throws Exception
{
JacksonXMLProvider prov = new JacksonXMLProvider();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Bean bean = new Bean();
Method m = getClass().getDeclaredMethod("bogus");
JsonView view = m.getAnnotation(JsonView.class);
assertNotNull(view); // just a sanity check
prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[] { view },
MediaType.APPLICATION_JSON_TYPE, null, out);
assertEquals("1 ", out.toString("UTF-8"));
}
}
TestRootType.java 0000664 0000000 0000000 00000003124 12373533575 0037754 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import java.io.ByteArrayOutputStream;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider;
public class TestRootType
extends JaxrsTestBase
{
@JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT, property="type")
@JsonTypeName("bean")
static class Bean {
public int a = 3;
}
public void testRootType() throws Exception
{
JacksonXMLProvider prov = new JacksonXMLProvider();
TypeReference> ref = new TypeReference>(){};
ArrayList list = new ArrayList();
list.add(new Bean());
list.add(new Bean());
ByteArrayOutputStream out = new ByteArrayOutputStream();
MediaType mt = MediaType.APPLICATION_JSON_TYPE;
prov.writeTo(list, List.class, ref.getType(), new Annotation[0], mt, null, out);
String xml = out.toString("UTF-8");
/* 09-Oct-2013, tatu: With 2.2, this produced "unwrapped" output; but
* with 2.3 it should use same defaults as XML module. So 'wrappers'
* are used for Collections, unless explicitly disabled.
*/
assertEquals("3 "
+"3
", xml);
}
}
TestSerialize.java 0000664 0000000 0000000 00000003760 12373533575 0040124 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import java.io.ByteArrayOutputStream;
import java.lang.annotation.Annotation;
import java.util.*;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonRootName;
public class TestSerialize extends JaxrsTestBase
{
// for [Issue-1]
public class Message {
public String text;
public Message() { }
public Message(String s) { text = s; }
}
@JsonRootName("m")
@JsonPropertyOrder({ "pageNumber", "messages" })
public class Messages {
protected List messages = new ArrayList();
protected int pageNumber;
protected Messages() {}
public Messages(List messages, int pageNumber) {
this.messages = messages;
this.pageNumber = pageNumber;
}
public List getMessages() {
return messages;
}
public int getPageNumber() {
return pageNumber;
}
}
/*
/**********************************************************************
/* Unit tests
/**********************************************************************
*/
// [Issue-1]
public void testSimpleWriteTo() throws Exception
{
Messages msgs = new Messages();
msgs.pageNumber = 3;
msgs.messages.add(new Message("foo"));
msgs.messages.add(new Message("bar"));
JacksonXMLProvider prov = new JacksonXMLProvider();
ByteArrayOutputStream out = new ByteArrayOutputStream();
MediaType mt = MediaType.APPLICATION_JSON_TYPE;
prov.writeTo(msgs, Messages.class, Messages.class, new Annotation[0], mt, null, out);
String xml = out.toString("UTF-8");
assertEquals("3 foo "
+"bar ",
xml);
}
}
TestUntouchables.java 0000664 0000000 0000000 00000004722 12373533575 0040630 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import java.util.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;
import com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider;
/**
* Unit tests for verifying that certain JDK base types will be
* ignored by default Jackson JAX-RS conversion provider.
*/
public class TestUntouchables
extends JaxrsTestBase
{
/**
* Test type added for [JACKSON-460]... just to ensure that "isXMLType"
* remains overridable.
*/
public static class MyJacksonProvider extends JacksonXMLProvider {
// ensure isJsonType remains "protected" � this is a compile-time check.
// Some users of JacksonJsonProvider override this method;
// changing to "private" would regress them.
@Override
protected boolean hasMatchingMediaType(MediaType mediaType) { return super.hasMatchingMediaType(mediaType); }
}
/*
/**********************************************************
/* Unit tests
/**********************************************************
*/
public void testDefaultUntouchables() throws Exception
{
JacksonXMLProvider prov = new JacksonXMLProvider();
// By default, no reason to exclude, say, this test class...
assertTrue(prov.isReadable(getClass(), getClass(), null, null));
assertTrue(prov.isWriteable(getClass(), getClass(), null, null));
// but some types should be ignored (set of ignorable may change over time tho!)
assertFalse(prov.isWriteable(StreamingOutput.class, StreamingOutput.class, null, null));
// and then on-the-fence things (see [Issue-1])
assertFalse(prov.isReadable(String.class, getClass(), null, null));
assertFalse(prov.isReadable(byte[].class, getClass(), null, null));
}
public void testCustomUntouchables() throws Exception
{
JacksonXMLProvider prov = new JacksonXMLProvider();
// can mark this as ignorable...
prov.addUntouchable(getClass());
// and then it shouldn't be processable
assertFalse(prov.isReadable(getClass(), getClass(), null, null));
assertFalse(prov.isWriteable(getClass(), getClass(), null, null));
// Same for interfaces, like:
prov.addUntouchable(Collection.class);
assertFalse(prov.isReadable(ArrayList.class, ArrayList.class, null, null));
assertFalse(prov.isWriteable(HashSet.class, HashSet.class, null, null));
}
}
TestXMLVersions.java 0000664 0000000 0000000 00000001511 12373533575 0040356 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml package com.fasterxml.jackson.jaxrs.xml;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider;
public class TestXMLVersions extends JaxrsTestBase
{
public void testMapperVersions()
{
assertVersion(new JacksonXMLProvider());
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
private void assertVersion(Versioned vers)
{
final Version v = vers.version();
assertFalse("Should find version information (got "+v+")", v.isUknownVersion());
Version exp = PackageVersion.VERSION;
assertEquals(exp.toFullString(), v.toFullString());
assertEquals(exp, v);
}
}
0000775 0000000 0000000 00000000000 12373533575 0035076 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml/dw ResourceTestBase.java 0000664 0000000 0000000 00000006040 12373533575 0041163 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml/dw package com.fasterxml.jackson.jaxrs.xml.dw;
import java.util.HashSet;
import java.util.Set;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.ws.rs.core.Application;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider;
import com.fasterxml.jackson.jaxrs.xml.JaxrsTestBase;
/**
* Intermediate base for tests that run actual full JAX-RS resource.
*/
public abstract class ResourceTestBase extends JaxrsTestBase
{
protected static abstract class XMLApplication extends Application
{
protected final Object _provider;
protected final Object _resource;
protected XMLApplication(Object provider, Object resource) {
_provider = provider;
_resource = resource;
}
@Override
public Set getSingletons() {
HashSet singletons = new HashSet();
singletons.add(_provider);
singletons.add(_resource);
return singletons;
}
}
protected static abstract class XMLApplicationWithJackson extends XMLApplication
{
public XMLApplicationWithJackson(Object resource) {
super(new JacksonXMLProvider(), resource);
}
}
/*
/**********************************************************
/* Abstract and overridable config methods
/**********************************************************
*/
protected abstract Class extends Servlet> servletContainerClass();
/*
/**********************************************************
/* Starting actual JAX-RS container
/**********************************************************
*/
protected Server startServer(int port, Class extends Application> appClass) {
return startServer(port, appClass, null);
}
protected Server startServer(int port, Class extends Application> appClass,
Class extends Filter> filterClass)
{
Server server = new Server(port);
final ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
ServletHolder jaxrs = new ServletHolder(servletContainerClass());
jaxrs.setInitParameter("javax.ws.rs.Application", appClass.getName());
final ServletContextHandler mainHandler = new ServletContextHandler(contexts, "/", true, false);
mainHandler.addServlet(jaxrs, "/*");
if (filterClass != null) {
mainHandler.addFilter(filterClass, "/*", java.util.EnumSet.allOf(DispatcherType.class));
}
server.setHandler(mainHandler);
try {
server.start();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return server;
}
}
SimpleEndpointTestBase.java 0000664 0000000 0000000 00000005753 12373533575 0042340 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml/dw package com.fasterxml.jackson.jaxrs.xml.dw;
import java.io.*;
import java.net.*;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.eclipse.jetty.server.Server;
import org.junit.Assert;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
public abstract class SimpleEndpointTestBase extends ResourceTestBase
{
final static int TEST_PORT = 6011;
static class Point {
public int x, y;
protected Point() { }
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
@Path("/point")
public static class SimpleResource
{
@GET
@Produces({ MediaType.APPLICATION_XML })
public Point getPoint() {
return new Point(1, 2);
}
}
public static class SimpleResourceApp extends XMLApplicationWithJackson {
public SimpleResourceApp() { super(new SimpleResource()); }
}
private final static byte[] UNTOUCHABLE_RESPONSE = new byte[] { 1, 2, 3, 4 };
@Path("/raw")
public static class RawResource
{
@GET
@Path("bytes")
@Produces({ MediaType.APPLICATION_XML })
public byte[] getBytes() throws IOException {
return UNTOUCHABLE_RESPONSE;
}
}
public static class SimpleRawApp extends XMLApplicationWithJackson {
public SimpleRawApp() { super(new RawResource()); }
}
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
public void testSimplePoint() throws Exception
{
final ObjectMapper mapper = new XmlMapper();
Server server = startServer(TEST_PORT, SimpleResourceApp.class);
Point p;
String xml = null;
try {
InputStream in = new URL("http://localhost:"+TEST_PORT+"/point").openStream();
byte[] bytes = readAll(in);
in.close();
xml = new String(bytes, "UTF-8");
p = mapper.readValue(xml, Point.class);
} finally {
server.stop();
}
// ensure we got a valid Point
assertNotNull(p);
assertEquals(1, p.x);
assertEquals(2, p.y);
if (xml.indexOf("1") < 0
|| xml.indexOf("2 ") < 0) {
fail("Expected Point to be serialized as XML, instead got: "+xml);
}
}
// [Issue#34] Verify that Untouchables act the way as they should
@SuppressWarnings("resource")
public void testUntouchables() throws Exception
{
Server server = startServer(TEST_PORT, SimpleRawApp.class);
try {
InputStream in = new URL("http://localhost:"+TEST_PORT+"/raw/bytes").openStream();
Assert.assertArrayEquals(UNTOUCHABLE_RESPONSE, readAll(in));
} finally {
server.stop();
}
}
}
0000775 0000000 0000000 00000000000 12373533575 0035765 5 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml/jersey SimpleEndpointTest.java 0000664 0000000 0000000 00000000604 12373533575 0042422 0 ustar 00root root 0000000 0000000 jackson-jaxrs-providers-jackson-jaxrs-providers-2.4.2/xml/src/test/java/com/fasterxml/jackson/jaxrs/xml/jersey package com.fasterxml.jackson.jaxrs.xml.jersey;
import javax.servlet.Servlet;
import com.fasterxml.jackson.jaxrs.xml.dw.SimpleEndpointTestBase;
import com.sun.jersey.spi.container.servlet.ServletContainer;
public class SimpleEndpointTest extends SimpleEndpointTestBase {
@Override
protected Class extends Servlet> servletContainerClass() { return ServletContainer.class; }
}