Skip to content

Commit 50e99d8

Browse files
committed
Issue RestExpress#106 - Deprecated RestExpress.setSerializationProvider() and RestExpress.getSerializationProvider() in favor of RestExpress.setDefaultSerializationProvider() and RestExpress.getDefaultSerializationProvider(). Also added new instance methods serializationProvider() to set and get the instance's serialization provider.
1 parent 9800802 commit 50e99d8

File tree

2 files changed

+71
-12
lines changed

2 files changed

+71
-12
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Release 0.11.1-SNAPSHOT - in 'master' branch
7979
* Fixed issue #110 - too many files open error.
8080
* Fixed issue #108 - request.getRemoteAddress() always returns null.
8181
* Fixed issue #94 - Load configuration properties from classpath (if available) and override with those loaded from file system.
82+
* Fixed issue #106 - Deprecated RestExpress.setSerializationProvider() and RestExpress.getSerializationProvider() in favor of RestExpress.setDefaultSerializationProvider() and RestExpress.getDefaultSerializationProvider(). Also added new instance methods
83+
serializationProvider() to set and get the instance's serialization provider.
8284
* Enhanced to use EPoll if it's available on the underlying OS.
8385
* Added support for ':in:' operator on query-string in filter operations (e.g. ?filter=name:in:a,b,c).
8486
* Introduced RestExpress.shutdown(boolean) to enable tests to optionally wait for a complete shutdown.

core/src/main/java/org/restexpress/RestExpress.java

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import io.netty.channel.group.ChannelGroup;
2525
import io.netty.channel.group.ChannelGroupFuture;
2626
import io.netty.channel.group.DefaultChannelGroup;
27-
import io.netty.util.ResourceLeakDetector;
28-
import io.netty.util.ResourceLeakDetector.Level;
2927
import io.netty.util.concurrent.DefaultEventExecutorGroup;
3028
import io.netty.util.concurrent.EventExecutorGroup;
3129
import io.netty.util.concurrent.GlobalEventExecutor;
@@ -73,17 +71,17 @@
7371
*/
7472
public class RestExpress
7573
{
76-
static
77-
{
78-
ResourceLeakDetector.setLevel(Level.DISABLED);
79-
}
74+
// static
75+
// {
76+
// ResourceLeakDetector.setLevel(Level.DISABLED);
77+
// }
8078

8179
private static final ChannelGroup allChannels = new DefaultChannelGroup("RestExpress", GlobalEventExecutor.INSTANCE);
8280

8381
public static final String DEFAULT_NAME = "RestExpress";
8482
public static final int DEFAULT_PORT = 8081;
8583

86-
private static SerializationProvider SERIALIZATION_PROVIDER = null;
84+
private static SerializationProvider DEFAULT_SERIALIZATION_PROVIDER = null;
8785

8886
private SocketSettings socketSettings = new SocketSettings();
8987
private ServerSettings serverSettings = new ServerSettings();
@@ -100,27 +98,86 @@ public class RestExpress
10098
private List<Plugin> plugins = new ArrayList<Plugin>();
10199
private RouteDeclaration routeDeclarations = new RouteDeclaration();
102100
private SSLContext sslContext = null;
101+
private SerializationProvider serializationProvider = null;
103102

104103
/**
105104
* Change the default behavior for serialization.
106105
* If no SerializationProcessor is set, default of DefaultSerializationProcessor is used,
107106
* which uses Jackson for JSON, XStream for XML.
108107
*
109108
* @param provider a SerializationProvider instance.
109+
* @deprecated use setDefaultSerializationProvider()
110110
*/
111111
public static void setSerializationProvider(SerializationProvider provider)
112112
{
113-
SERIALIZATION_PROVIDER = provider;
113+
setDefaultSerializationProvider(provider);
114114
}
115115

116+
/**
117+
* @return the default serialization provider.
118+
* @deprecated Use getDefaultSerializationProvider()
119+
*/
116120
public static SerializationProvider getSerializationProvider()
117121
{
118-
if (SERIALIZATION_PROVIDER == null)
122+
return getDefaultSerializationProvider();
123+
}
124+
125+
/**
126+
* Change the default behavior for serialization.
127+
* If no SerializationProvider is set, default of DefaultSerializationProvider is used,
128+
* which uses Jackson for JSON, XStream for XML.
129+
*
130+
* @param provider a SerializationProvider instance.
131+
*/
132+
public static void setDefaultSerializationProvider(SerializationProvider provider)
133+
{
134+
DEFAULT_SERIALIZATION_PROVIDER = provider;
135+
}
136+
137+
/**
138+
* Get the default serialization provider for RestExpress. If the value is
139+
* unset DefaultSerializationProcessor is set as the default and returned.
140+
* Otherwise, the previously-set value for the default is returned.
141+
*
142+
* @return the default serialization provider.
143+
*/
144+
public static SerializationProvider getDefaultSerializationProvider()
145+
{
146+
if (DEFAULT_SERIALIZATION_PROVIDER == null)
147+
{
148+
DEFAULT_SERIALIZATION_PROVIDER = new DefaultSerializationProvider();
149+
}
150+
151+
return DEFAULT_SERIALIZATION_PROVIDER;
152+
}
153+
154+
/**
155+
* Change the serialization provider for this server instance.
156+
* If no SerializationProcessor is set, default of DefaultSerializationProcessor is used,
157+
* which uses Jackson for JSON, XStream for XML.
158+
*
159+
* @param provider a SerializationProvider instance.
160+
*/
161+
public void serializationProvider(SerializationProvider provider)
162+
{
163+
this.serializationProvider = provider;
164+
}
165+
166+
/**
167+
* Get the serialization provider for this server instance. If none has
168+
* been set, it is set to the default serialization processor and returned.
169+
* Otherwise, the setting for this server is returned.
170+
*
171+
* @return the SerializationProvider for this instance, or the default.
172+
*/
173+
public SerializationProvider serializationProvider()
174+
{
175+
if (serializationProvider == null)
119176
{
120-
SERIALIZATION_PROVIDER = new DefaultSerializationProvider();
177+
serializationProvider(getDefaultSerializationProvider());
121178
}
122179

123-
return SERIALIZATION_PROVIDER;
180+
return serializationProvider;
124181
}
125182

126183
/**
@@ -523,7 +580,7 @@ public ChannelHandler buildRequestHandler()
523580
{
524581
// Set up the event pipeline factory.
525582
DefaultRequestHandler requestHandler = new DefaultRequestHandler(
526-
createRouteResolver(), getSerializationProvider(),
583+
createRouteResolver(), serializationProvider(),
527584
new DefaultHttpResponseWriter(), enforceHttpSpec);
528585

529586
// Add MessageObservers to the request handler here, if desired...

0 commit comments

Comments
 (0)