-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
…eed to rework
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ public abstract class ProviderBase< | |
* (never try to serialize instances of these types). | ||
*/ | ||
public final static Class<?>[] DEFAULT_UNWRITABLES = new Class<?>[] { | ||
InputStream.class, // as per [Issue#19] | ||
InputStream.class, // as per [Issue#19] | ||
OutputStream.class, Writer.class, | ||
StreamingOutput.class, Response.class | ||
}; | ||
|
@@ -112,7 +112,7 @@ public abstract class ProviderBase< | |
/** | ||
* Feature flags set. | ||
* | ||
* @since 2.3.0 | ||
* @since 2.3 | ||
*/ | ||
protected int _jaxRSFeatures; | ||
|
||
|
@@ -125,6 +125,20 @@ public abstract class ProviderBase< | |
* View to use for writing if none defined for the end point. | ||
*/ | ||
protected Class<?> _defaultWriteView; | ||
|
||
/** | ||
* Object used for handling possible {@link ObjectReader} injection. | ||
* | ||
* @since 2.3 | ||
*/ | ||
protected ObjectReaderInjector _readerInjector; | ||
|
||
/** | ||
* Object used for handling possible {@link ObjectWriter} injection. | ||
* | ||
* @since 2.3 | ||
*/ | ||
protected ObjectWriterInjector _writerInjector; | ||
|
||
/* | ||
/********************************************************** | ||
|
@@ -176,6 +190,8 @@ public abstract class ProviderBase< | |
|
||
protected ProviderBase(MAPPER_CONFIG mconfig) { | ||
_mapperConfig = mconfig; | ||
_readerInjector = new ObjectReaderInjector(); | ||
_writerInjector = new ObjectWriterInjector(); | ||
} | ||
|
||
/** | ||
|
@@ -446,11 +462,43 @@ protected boolean hasMatchingMediaTypeForWriting(MediaType mediaType) { | |
|
||
protected abstract MAPPER _locateMapperViaProvider(Class<?> type, MediaType mediaType); | ||
|
||
protected abstract EP_CONFIG _configForReading(MAPPER mapper, | ||
Annotation[] annotations, Class<?> defaultView); | ||
protected EP_CONFIG _configForReading(MAPPER mapper, | ||
Annotation[] annotations, Class<?> defaultView) | ||
{ | ||
ObjectReader r = _readerInjector.getAndClear(); | ||
if (r == null) { | ||
if (defaultView != null) { | ||
r = mapper.readerWithView(defaultView); | ||
} else { | ||
r = mapper.reader(); | ||
} | ||
} else { | ||
r = r.withView(defaultView); | ||
} | ||
return _configForReading(r, annotations); | ||
} | ||
|
||
protected EP_CONFIG _configForWriting(MAPPER mapper, | ||
Annotation[] annotations, Class<?> defaultView) | ||
{ | ||
ObjectWriter w = _writerInjector.getAndClear(); | ||
if (w == null) { | ||
if (defaultView != null) { | ||
w = mapper.writerWithView(defaultView); | ||
} else { | ||
w = mapper.writer(); | ||
} | ||
} else { | ||
w = w.withView(defaultView); | ||
} | ||
return _configForWriting(w, annotations); | ||
} | ||
|
||
protected abstract EP_CONFIG _configForReading(ObjectReader reader, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cowtowncoder
Author
Member
|
||
Annotation[] annotations); | ||
|
||
protected abstract EP_CONFIG _configForWriting(MAPPER mapper, | ||
Annotation[] annotations, Class<?> defaultView); | ||
protected abstract EP_CONFIG _configForWriting(ObjectWriter writer, | ||
Annotation[] annotations); | ||
|
||
/* | ||
/********************************************************** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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 ObjectReader} | ||
* that JAX-RS Resource will use; usually this is done from a Servlet or JAX-RS filter | ||
* before execution reaches resource. | ||
* | ||
* @author apemberton@github, Tatu Saloranta | ||
* | ||
* @since 2.3 | ||
*/ | ||
public class ObjectReaderInjector | ||
{ | ||
protected static final ThreadLocal<ObjectReader> _threadLocal = new ThreadLocal<ObjectReader>(); | ||
|
||
/** | ||
* Simple marker used to optimize out {@link ThreadLocal} access in cases | ||
* where this feature is not being used | ||
*/ | ||
protected final AtomicBoolean _hasBeenSet = new AtomicBoolean(false); | ||
|
||
public ObjectReaderInjector() { } | ||
|
||
public void set(ObjectReader r) { | ||
_hasBeenSet.set(true); | ||
_threadLocal.set(r); | ||
} | ||
|
||
public ObjectReader get() { | ||
return _hasBeenSet.get() ? _threadLocal.get() : null; | ||
} | ||
|
||
public ObjectReader getAndClear() { | ||
ObjectReader r = get(); | ||
if (r != null) { | ||
_threadLocal.remove(); | ||
} | ||
return r; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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. | ||
* | ||
* @author apemberton@github, Tatu Saloranta | ||
* | ||
* @since 2.3 | ||
*/ | ||
public class ObjectWriterInjector | ||
{ | ||
protected static final ThreadLocal<ObjectWriter> _threadLocal = new ThreadLocal<ObjectWriter>(); | ||
|
||
/** | ||
* Simple marker used to optimize out {@link ThreadLocal} access in cases | ||
* where this feature is not being used | ||
*/ | ||
protected final AtomicBoolean _hasBeenSet = new AtomicBoolean(false); | ||
|
||
public ObjectWriterInjector() { } | ||
|
||
public void set(ObjectWriter r) { | ||
_hasBeenSet.set(true); | ||
_threadLocal.set(r); | ||
} | ||
|
||
public ObjectWriter get() { | ||
return _hasBeenSet.get() ? _threadLocal.get() : null; | ||
} | ||
|
||
public ObjectWriter getAndClear() { | ||
ObjectWriter w = get(); | ||
if (w != null) { | ||
_threadLocal.remove(); | ||
} | ||
return w; | ||
} | ||
} |
You just broke Resteasy: https://github.com/resteasy/Resteasy/blob/e30b28d6cdd2cdfaaa90e94c471ae88d6b813bbe/jaxrs/providers/jackson2/src/main/java/org/jboss/resteasy/plugins/providers/jackson/ResteasyJackson2Provider.java#L107
I'm using Jongo which uses Jackson 2.3, and Resteasy only works with 2.2 because of this breaking change.
Now maybe Resteasy's provider is not needed anymore (except for their
@NoJackson
annotation, but I don't use it).