[
https://issues.apache.org/jira/browse/WW-4989?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16721427#comment-16721427
]
ASF GitHub Bot commented on WW-4989:
------------------------------------
yasserzamani closed pull request #288: [WW-4989] Uses JacksonXML handler a
default handler for XML in the REST plugin
URL: https://github.com/apache/struts/pull/288
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JacksonLibHandler.java
b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JacksonJsonHandler.java
similarity index 97%
rename from
plugins/rest/src/main/java/org/apache/struts2/rest/handler/JacksonLibHandler.java
rename to
plugins/rest/src/main/java/org/apache/struts2/rest/handler/JacksonJsonHandler.java
index a1bcf8e03..9a3c0c599 100644
---
a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JacksonLibHandler.java
+++
b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JacksonJsonHandler.java
@@ -32,7 +32,7 @@
/**
* Handles JSON content using jackson-lib
*/
-public class JacksonLibHandler extends AbstractContentTypeHandler {
+public class JacksonJsonHandler extends AbstractContentTypeHandler {
private static final String DEFAULT_CONTENT_TYPE = "application/json";
private String defaultEncoding = "ISO-8859-1";
diff --git a/plugins/rest/src/main/resources/struts-plugin.xml
b/plugins/rest/src/main/resources/struts-plugin.xml
index 62be4e458..1dd8d9dcb 100644
--- a/plugins/rest/src/main/resources/struts-plugin.xml
+++ b/plugins/rest/src/main/resources/struts-plugin.xml
@@ -30,8 +30,8 @@
<bean type="org.apache.struts2.rest.ContentTypeHandlerManager"
class="org.apache.struts2.rest.DefaultContentTypeHandlerManager" />
- <bean type="org.apache.struts2.rest.handler.ContentTypeHandler" name="xml"
class="org.apache.struts2.rest.handler.XStreamHandler" />
- <bean type="org.apache.struts2.rest.handler.ContentTypeHandler"
name="json" class="org.apache.struts2.rest.handler.JacksonLibHandler" />
+ <bean type="org.apache.struts2.rest.handler.ContentTypeHandler" name="xml"
class="org.apache.struts2.rest.handler.JacksonXmlHandler" />
+ <bean type="org.apache.struts2.rest.handler.ContentTypeHandler"
name="json" class="org.apache.struts2.rest.handler.JacksonJsonHandler" />
<bean type="org.apache.struts2.rest.handler.ContentTypeHandler"
name="html" class="org.apache.struts2.rest.handler.HtmlHandler" />
<bean type="org.apache.struts2.rest.handler.ContentTypeHandler"
name="x-www-form-urlencoded"
class="org.apache.struts2.rest.handler.FormUrlEncodedHandler" />
<bean type="org.apache.struts2.rest.handler.ContentTypeHandler"
name="multipart/form-data"
class="org.apache.struts2.rest.handler.MultipartFormDataHandler" />
diff --git
a/plugins/rest/src/test/java/org/apache/struts2/rest/handler/JacksonLibHandlerTest.java
b/plugins/rest/src/test/java/org/apache/struts2/rest/handler/JacksonJsonHandlerTest.java
similarity index 88%
rename from
plugins/rest/src/test/java/org/apache/struts2/rest/handler/JacksonLibHandlerTest.java
rename to
plugins/rest/src/test/java/org/apache/struts2/rest/handler/JacksonJsonHandlerTest.java
index 979b094d1..537e088a0 100644
---
a/plugins/rest/src/test/java/org/apache/struts2/rest/handler/JacksonLibHandlerTest.java
+++
b/plugins/rest/src/test/java/org/apache/struts2/rest/handler/JacksonJsonHandlerTest.java
@@ -28,13 +28,13 @@
import java.util.Arrays;
import java.util.List;
-public class JacksonLibHandlerTest extends TestCase {
+public class JacksonJsonHandlerTest extends TestCase {
public void testFromObject() throws IOException {
Contact contact = new Contact("bob", true, 44);
StringWriter writer = new StringWriter();
- JacksonLibHandler handler = new JacksonLibHandler();
+ JacksonJsonHandler handler = new JacksonJsonHandler();
handler.fromObject(new MockActionInvocation(), contact, "success",
writer);
String data = writer.toString();
assertTrue(data.startsWith("{"));
@@ -47,7 +47,7 @@ public void testFromObjectArray() throws IOException {
Contact contact = new Contact("bob", true, 44);
StringWriter writer = new StringWriter();
- JacksonLibHandler handler = new JacksonLibHandler();
+ JacksonJsonHandler handler = new JacksonJsonHandler();
handler.fromObject(new MockActionInvocation(), Arrays.asList(contact),
"success", writer);
String data = writer.toString();
@@ -62,7 +62,7 @@ public void testToObject() throws IOException {
Contact target = new Contact();
StringReader reader = new
StringReader("{\"age\":44,\"important\":true,\"name\":\"bob\"}");
- JacksonLibHandler handler = new JacksonLibHandler();
+ JacksonJsonHandler handler = new JacksonJsonHandler();
handler.toObject(new MockActionInvocation(), reader, target);
assertEquals(contact, target);
}
@@ -75,18 +75,18 @@ public void testToObjectList() throws IOException {
List<Contact> target = new ArrayList<Contact>();
StringReader reader = new
StringReader("[{\"age\":44,\"important\":true,\"name\":\"bob\"},{\"age\":33,\"important\":false,\"name\":\"john\"}]");
- JacksonLibHandler handler = new JacksonLibHandler();
+ JacksonJsonHandler handler = new JacksonJsonHandler();
handler.toObject(new MockActionInvocation(), reader, target);
assertEquals(source.size(), target.size());
}
public void testContentType() throws IOException {
- JacksonLibHandler handler = new JacksonLibHandler();
+ JacksonJsonHandler handler = new JacksonJsonHandler();
assertEquals(handler.getContentType(),
"application/json;charset=ISO-8859-1");
}
public void testDefaultEncoding() throws IOException {
- JacksonLibHandler handler = new JacksonLibHandler();
+ JacksonJsonHandler handler = new JacksonJsonHandler();
handler.setDefaultEncoding("UTF-8");
assertEquals(handler.getContentType(),
"application/json;charset=UTF-8");
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Use JacksonXML handler instead of XStream as a default handler for XML in the
> REST plugin
> -----------------------------------------------------------------------------------------
>
> Key: WW-4989
> URL: https://issues.apache.org/jira/browse/WW-4989
> Project: Struts 2
> Issue Type: Dependency
> Components: Plugin - REST
> Reporter: Lukasz Lenart
> Assignee: Lukasz Lenart
> Priority: Major
> Fix For: 2.6
>
>
> XStream library isn't actively developed but still maintained. Switching to
> JacksonXML is just a matter of a simple change in struts.xml. Backward
> compatibility will be kept by allowing users to use the existing XStream
> handler as optional to JacksonXML.
> https://struts.apache.org/plugins/rest/#custom-contenttypehandlers
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)