mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-3545 - remove comments for JSON output
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1144259 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+3
-3
@@ -106,7 +106,7 @@ public class JSONValidationInterceptor extends MethodFilterInterceptor {
|
||||
if (isValidateOnly(request)) {
|
||||
//there were no errors
|
||||
setupEncoding(response, request);
|
||||
response.getWriter().print("/* {} */");
|
||||
response.getWriter().print("{}");
|
||||
response.setContentType("application/json");
|
||||
return Action.NONE;
|
||||
} else {
|
||||
@@ -159,7 +159,7 @@ public class JSONValidationInterceptor extends MethodFilterInterceptor {
|
||||
protected String buildResponse(ValidationAware validationAware) {
|
||||
//should we use FreeMarker here?
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("/* { ");
|
||||
sb.append("{ ");
|
||||
|
||||
if (validationAware.hasErrors()) {
|
||||
//action errors
|
||||
@@ -192,7 +192,7 @@ public class JSONValidationInterceptor extends MethodFilterInterceptor {
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("} */");
|
||||
sb.append("}");
|
||||
/*response should be something like:
|
||||
* {
|
||||
* "errors": ["this", "that"],
|
||||
|
||||
+16
-20
@@ -21,13 +21,16 @@
|
||||
|
||||
package org.apache.struts2.interceptor.validation;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.mock.MockActionProxy;
|
||||
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.Validation;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.TestUtils;
|
||||
@@ -35,18 +38,11 @@ import org.apache.struts2.views.jsp.StrutsMockHttpServletRequest;
|
||||
import org.apache.struts2.views.jsp.StrutsMockHttpServletResponse;
|
||||
import org.apache.struts2.views.jsp.StrutsMockServletContext;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.mock.MockActionProxy;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.Validation;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JSONValidationInterceptorTest extends StrutsTestCase {
|
||||
private MockActionInvocation invocation;
|
||||
@@ -121,7 +117,7 @@ public class JSONValidationInterceptorTest extends StrutsTestCase {
|
||||
String json = stringWriter.toString();
|
||||
|
||||
String normalizedActual = TestUtils.normalize(json, true);
|
||||
assertEquals("/*{}*/", normalizedActual);
|
||||
assertEquals("{}", normalizedActual);
|
||||
assertFalse(action.isExecuted());
|
||||
assertEquals("application/json", response.getContentType());
|
||||
assertEquals("UTF-8", response.getCharacterEncoding());
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* {
|
||||
{
|
||||
"errors": [
|
||||
"General error"
|
||||
],
|
||||
@@ -9,4 +9,4 @@
|
||||
"This is no email"
|
||||
]
|
||||
}
|
||||
} */
|
||||
}
|
||||
Reference in New Issue
Block a user