Skip to content

Commit

Permalink
fix(echo) Automatically recognizes and removes string symbols.
Browse files Browse the repository at this point in the history
  • Loading branch information
yizzuide committed Nov 18, 2020
1 parent 90b7005 commit 67688f1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Milkomeda/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<properties>
<java.version>1.8</java.version>
<project.release.version>3.12.6-SNAPSHOT</project.release.version>
<project.release.version>3.12.7-SNAPSHOT</project.release.version>
<spring-boot.version>2.2.4</spring-boot.version>
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
<mybatis.starter.version>2.1.1</mybatis.starter.version>
Expand Down Expand Up @@ -67,7 +67,7 @@
<profile>
<id>sonatype-oss-release</id>
<properties>
<project.release.version>3.12.6</project.release.version>
<project.release.version>3.12.7</project.release.version>
</properties>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @author yizzuide
* @since 1.13.0
* @version 3.12.3
* @version 3.12.7
* Create at 2019/09/21 19:00
*/
@Slf4j
Expand Down Expand Up @@ -104,11 +104,18 @@ protected <T> EchoResponseData<T> createReturnData(Object respData, TypeReferenc
if (isStringType) {
return responseData;
}
String dataStr = (String) responseData.getData();
if (dataStr.startsWith("\"")) {
dataStr = dataStr.substring(1);
}
if (dataStr.endsWith("\"")) {
dataStr = dataStr.substring(0, dataStr.length() - 1);
}
if (forceCamel) {
responseData.setData(JSONUtil.toCamel(responseData.getData(), specType));
responseData.setData(JSONUtil.toCamel(dataStr, specType));
return responseData;
}
responseData.setData(JSONUtil.nativeRead((String) responseData.getData(), specType));
responseData.setData(JSONUtil.nativeRead(dataStr, specType));
return responseData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
* Create at 2020/04/03 11:02
*/
public abstract class AbstractInterceptorLoader<T> extends AbstractHydrogenLoader<T> implements InterceptorLoader {
// Keep empty, prepare extend later.
// Keep empty, prepare extend later
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
Expand All @@ -20,7 +21,6 @@
import javax.annotation.PostConstruct;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -79,7 +79,7 @@ public void init() {

// 4xx异常处理
@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, @Nullable Object body, HttpHeaders headers, HttpStatus status, WebRequest request) {
protected @NonNull ResponseEntity<Object> handleExceptionInternal(@NonNull Exception ex, @Nullable Object body, @NonNull HttpHeaders headers, HttpStatus status, @NonNull WebRequest request) {
ResponseEntity<Object> responseEntity = handleExceptionResponse(ex, status.value(), ex.getMessage());
if (responseEntity == null) {
return super.handleExceptionInternal(ex, body, headers, status, request);
Expand All @@ -101,22 +101,22 @@ public ResponseEntity<Object> constraintViolationException(ConstraintViolationEx

// 对方法上@RequestBody的Bean参数校验的处理
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
protected @NonNull ResponseEntity<Object> handleMethodArgumentNotValid(@NonNull MethodArgumentNotValidException ex, @NonNull HttpHeaders headers, @NonNull HttpStatus status, @NonNull WebRequest request) {
ResponseEntity<Object> responseEntity = handleValidBeanExceptionResponse(ex, ex.getBindingResult());
return responseEntity == null ? super.handleMethodArgumentNotValid(ex, headers, status, request) : responseEntity;
}

// 对方法的Form提交参数绑定校验的处理
@Override
protected ResponseEntity<Object> handleBindException(BindException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
protected @NonNull ResponseEntity<Object> handleBindException(@NonNull BindException ex, @NonNull HttpHeaders headers, @NonNull HttpStatus status, @NonNull WebRequest request) {
ResponseEntity<Object> responseEntity = handleValidBeanExceptionResponse(ex, ex.getBindingResult());
return responseEntity == null ? super.handleBindException(ex, headers, status, request) : responseEntity;
}

// 其它内部异常处理
@SuppressWarnings("unchecked")
@ExceptionHandler(Exception.class)
public ResponseEntity<Object> handleException(Exception e) throws IOException {
public ResponseEntity<Object> handleException(Exception e) {
Map<String, Object> response = props.getResponse();
Object status = response.get(YmlResponseOutput.STATUS);
status = status == null ? 500 : status;
Expand Down Expand Up @@ -164,7 +164,7 @@ private ResponseEntity<Object> handleValidBeanExceptionResponse(Exception ex, Bi
* @return ResponseEntity
*/
@SuppressWarnings("unchecked")
private ResponseEntity<Object> handleExceptionResponse(Exception ex, Object presetStatusCode, String presetMessage) {
private @Nullable ResponseEntity<Object> handleExceptionResponse(Exception ex, Object presetStatusCode, String presetMessage) {
Map<String, Object> response = props.getResponse();
Map<String, Object> result = new HashMap<>();
Object exp4xx = response.get(presetStatusCode.toString());
Expand Down
2 changes: 1 addition & 1 deletion MilkomedaDemo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
<milkomeda.version>3.12.6-SNAPSHOT</milkomeda.version>
<milkomeda.version>3.12.7-SNAPSHOT</milkomeda.version>
<mybatis.starter>2.1.1</mybatis.starter>
<redission.version>3.12.5</redission.version>
<zookeeper.version>3.4.14</zookeeper.version>
Expand Down

0 comments on commit 67688f1

Please sign in to comment.