RetResult增加Convert属性
This commit is contained in:
@@ -390,7 +390,9 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
this.header.addValue("retcode", String.valueOf(ret.getRetcode()));
|
this.header.addValue("retcode", String.valueOf(ret.getRetcode()));
|
||||||
this.header.addValue("retinfo", ret.getRetinfo());
|
this.header.addValue("retinfo", ret.getRetinfo());
|
||||||
}
|
}
|
||||||
finish(request.getJsonConvert().convertTo(getBodyBufferSupplier(), ret));
|
Convert convert = ret == null ? null : ret.convert();
|
||||||
|
if (convert == null) convert = request.getJsonConvert();
|
||||||
|
finish(convert.convertTo(getBodyBufferSupplier(), ret));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -497,6 +499,8 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
context.getLogger().log(Level.WARNING, "HttpServlet finish File occur, force to close channel. request = " + getRequest(), e);
|
context.getLogger().log(Level.WARNING, "HttpServlet finish File occur, force to close channel. request = " + getRequest(), e);
|
||||||
finish(500, null);
|
finish(500, null);
|
||||||
}
|
}
|
||||||
|
} else if (obj instanceof org.redkale.service.RetResult) {
|
||||||
|
finishJson((org.redkale.service.RetResult) obj);
|
||||||
} else if (obj instanceof HttpResult) {
|
} else if (obj instanceof HttpResult) {
|
||||||
HttpResult result = (HttpResult) obj;
|
HttpResult result = (HttpResult) obj;
|
||||||
if (result.getContentType() != null) setContentType(result.getContentType());
|
if (result.getContentType() != null) setContentType(result.getContentType());
|
||||||
@@ -506,7 +510,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
} else if (result.getResult() instanceof CharSequence) {
|
} else if (result.getResult() instanceof CharSequence) {
|
||||||
finish(result.getResult().toString());
|
finish(result.getResult().toString());
|
||||||
} else {
|
} else {
|
||||||
finish(result.getConvert() == null ? convert : result.getConvert(), result.getResult());
|
finish(result.convert() == null ? convert : result.convert(), result.getResult());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (hasRender) {
|
if (hasRender) {
|
||||||
|
|||||||
@@ -90,12 +90,11 @@ public class HttpResult<T> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConvertDisabled
|
public Convert convert() {
|
||||||
public Convert getConvert() {
|
|
||||||
return convert;
|
return convert;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConvert(Convert convert) {
|
public void convert(Convert convert) {
|
||||||
this.convert = convert;
|
this.convert = convert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ package org.redkale.service;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import org.redkale.convert.Convert;
|
||||||
import org.redkale.convert.json.*;
|
import org.redkale.convert.json.*;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
@@ -33,6 +34,8 @@ public class RetResult<T> {
|
|||||||
|
|
||||||
protected Map<String, String> attach;
|
protected Map<String, String> attach;
|
||||||
|
|
||||||
|
protected Convert convert;
|
||||||
|
|
||||||
public RetResult() {
|
public RetResult() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +43,11 @@ public class RetResult<T> {
|
|||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RetResult(Convert convert, T result) {
|
||||||
|
this.convert = convert;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
public RetResult(int retcode) {
|
public RetResult(int retcode) {
|
||||||
this.retcode = retcode;
|
this.retcode = retcode;
|
||||||
}
|
}
|
||||||
@@ -55,6 +63,14 @@ public class RetResult<T> {
|
|||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Convert convert() {
|
||||||
|
return convert;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void convert(Convert convert) {
|
||||||
|
this.convert = convert;
|
||||||
|
}
|
||||||
|
|
||||||
public static RetResult success() {
|
public static RetResult success() {
|
||||||
return new RetResult();
|
return new RetResult();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user