[jackson-jaxrs-providers] 119/162: Fix #40
Timo Aaltonen
tjaalton at moszumanska.debian.org
Mon Sep 8 22:16:34 UTC 2014
This is an automated email from the git hooks/post-receive script.
tjaalton pushed a commit to branch master
in repository jackson-jaxrs-providers.
commit 96686b0b5a947b493326fee0660e35fca559c1af
Author: Tatu Saloranta <tatu.saloranta at iki.fi>
Date: Thu Jan 30 20:57:12 2014 -0800
Fix #40
---
.../jackson/jaxrs/json/JacksonJsonProvider.java | 5 ++-
.../jaxrs/json/dw/SimpleEndpointTestBase.java | 46 ++++++++++++++++------
release-notes/VERSION | 11 ++++--
3 files changed, 47 insertions(+), 15 deletions(-)
diff --git a/json/src/main/java/com/fasterxml/jackson/jaxrs/json/JacksonJsonProvider.java b/json/src/main/java/com/fasterxml/jackson/jaxrs/json/JacksonJsonProvider.java
index 933ec1a..753927a 100644
--- a/json/src/main/java/com/fasterxml/jackson/jaxrs/json/JacksonJsonProvider.java
+++ b/json/src/main/java/com/fasterxml/jackson/jaxrs/json/JacksonJsonProvider.java
@@ -168,6 +168,7 @@ public class JacksonJsonProvider
* 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
*/
@@ -183,11 +184,13 @@ public class JacksonJsonProvider
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")
+ 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
diff --git a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/SimpleEndpointTestBase.java b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/SimpleEndpointTestBase.java
index f2b6344..19c280a 100644
--- a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/SimpleEndpointTestBase.java
+++ b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/SimpleEndpointTestBase.java
@@ -30,9 +30,17 @@ public abstract class SimpleEndpointTestBase extends ResourceTestBase
@Path("/point")
public static class SimpleResource
{
+ @Path("/javascript")
@GET
@Produces({ MediaType.APPLICATION_JSON, "application/javascript" })
- public Point getPoint() {
+ 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);
}
}
@@ -75,13 +83,13 @@ public abstract class SimpleEndpointTestBase extends ResourceTestBase
{
final ObjectMapper mapper = new ObjectMapper();
Server server = startServer(TEST_PORT, SimpleResourceApp.class);
- InputStream in = new URL("http://localhost:"+TEST_PORT+"/point").openStream();
Point p;
try {
+ InputStream in = new URL("http://localhost:"+TEST_PORT+"/point/javascript").openStream();
p = mapper.readValue(in, Point.class);
- } finally {
in.close();
+ } finally {
server.stop();
}
// ensure we got a valid Point
@@ -89,15 +97,16 @@ public abstract class SimpleEndpointTestBase extends ResourceTestBase
assertEquals(1, p.x);
assertEquals(2, p.y);
}
-
+
public void testAcceptJavascriptType() throws Exception
{
final ObjectMapper mapper = new ObjectMapper();
- Server server = startServer(6062, SimpleResourceApp.class);
- URL url = new URL("http://localhost:6062/point");
+ 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) url.openConnection();
+ HttpURLConnection conn = (HttpURLConnection) urlJS.openConnection();
// First: verify that weird types are not supported...
conn.setRequestProperty("Accept", "foo/bar");
@@ -106,9 +115,8 @@ public abstract class SimpleEndpointTestBase extends ResourceTestBase
conn.disconnect();
// try again with somewhat non-standard, but supported JSON-like type (application/javascript)
- conn = (HttpURLConnection) url.openConnection();
+ conn = (HttpURLConnection) urlJS.openConnection();
conn.setRequestProperty("Accept", "application/javascript");
-// conn.setRequestProperty("Accept", "application/json");
assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
InputStream in = conn.getInputStream();
Point p;
@@ -120,12 +128,28 @@ public abstract class SimpleEndpointTestBase extends ResourceTestBase
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
diff --git a/release-notes/VERSION b/release-notes/VERSION
index a718aec..da8be3f 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -4,15 +4,20 @@ Sub-modules:
jackson-jaxrs-smile-provider
jackson-jaxrs-xml-provider
-2.3.1 (28-Dec-2013)
+2.3.2 (xx-xxx-2014)
-#37: Enable use of JAX-RS 2.0 API
- (contributed by larsp at github)
+#40: Allow use of "text/x-json" content type by default
+ (requested by kdeenanauth at github)
------------------------------------------------------------------------
=== History: ===
------------------------------------------------------------------------
+2.3.1 (28-Dec-2013)
+
+#37: Enable use of JAX-RS 2.0 API
+ (contributed by larsp at github)
+
2.3.0 (14-Nov-2013)
#24: Allow defining default view to use for endpoints without View annotation
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jackson-jaxrs-providers.git
More information about the pkg-java-commits
mailing list