This commit is contained in:
@@ -36,7 +36,7 @@ public abstract class Convert<R extends Reader, W extends Writer> {
|
||||
return writer;
|
||||
}
|
||||
|
||||
protected <S extends W> S fieldFunc(S writer, BiFunction<Attribute, Object, Object> objFieldFunc, Function<Object, EnFieldObject[]> objExtFunc) {
|
||||
protected <S extends W> S fieldFunc(S writer, BiFunction<Attribute, Object, Object> objFieldFunc, Function<Object, EnFieldValue[]> objExtFunc) {
|
||||
writer.objFieldFunc = objFieldFunc;
|
||||
writer.objExtFunc = objExtFunc;
|
||||
return writer;
|
||||
@@ -44,7 +44,7 @@ public abstract class Convert<R extends Reader, W extends Writer> {
|
||||
|
||||
public abstract Convert<R, W> newConvert(final BiFunction<Attribute, Object, Object> objFieldFunc);
|
||||
|
||||
public abstract Convert<R, W> newConvert(final BiFunction<Attribute, Object, Object> objFieldFunc, Function<Object, EnFieldObject[]> objExtFunc);
|
||||
public abstract Convert<R, W> newConvert(final BiFunction<Attribute, Object, Object> objFieldFunc, Function<Object, EnFieldValue[]> objExtFunc);
|
||||
|
||||
public abstract boolean isBinary();
|
||||
|
||||
|
||||
@@ -170,10 +170,10 @@ public class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T> {
|
||||
out.writeObjectField(member, value);
|
||||
}
|
||||
if (out.objExtFunc != null) {
|
||||
EnFieldObject[] extFields = out.objExtFunc.apply(value);
|
||||
EnFieldValue[] extFields = out.objExtFunc.apply(value);
|
||||
if (extFields != null) {
|
||||
Encodeable<W, ?> anyEncoder = factory.getAnyEncoder();
|
||||
for (EnFieldObject en : extFields) {
|
||||
for (EnFieldValue en : extFields) {
|
||||
if (en == null) continue;
|
||||
maxPosition++;
|
||||
out.writeObjectField(en.getName(), en.getType(), Math.max(en.getPosition(), maxPosition), anyEncoder, en.getValue());
|
||||
|
||||
@@ -29,7 +29,7 @@ public abstract class Writer {
|
||||
protected BiFunction<Attribute, Object, Object> objFieldFunc;
|
||||
|
||||
//对某个对象进行动态扩展字段值处理
|
||||
protected Function<Object, EnFieldObject[]> objExtFunc;
|
||||
protected Function<Object, EnFieldValue[]> objExtFunc;
|
||||
|
||||
/**
|
||||
* 设置specify
|
||||
|
||||
@@ -65,7 +65,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BsonConvert newConvert(final BiFunction<Attribute, Object, Object> fieldFunc, Function<Object, EnFieldObject[]> objExtFunc) {
|
||||
public BsonConvert newConvert(final BiFunction<Attribute, Object, Object> fieldFunc, Function<Object, EnFieldValue[]> objExtFunc) {
|
||||
return new BsonConvert(getFactory(), tiny) {
|
||||
@Override
|
||||
protected <S extends BsonWriter> S configWrite(S writer) {
|
||||
|
||||
@@ -52,7 +52,7 @@ public class JsonConvert extends TextConvert<JsonReader, JsonWriter> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonConvert newConvert(final BiFunction<Attribute, Object, Object> fieldFunc, Function<Object, EnFieldObject[]> objExtFunc) {
|
||||
public JsonConvert newConvert(final BiFunction<Attribute, Object, Object> fieldFunc, Function<Object, EnFieldValue[]> objExtFunc) {
|
||||
return new JsonConvert(getFactory(), tiny) {
|
||||
@Override
|
||||
protected <S extends JsonWriter> S configWrite(S writer) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import org.redkale.convert.EnFieldObject;
|
||||
import org.redkale.convert.EnFieldValue;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.Attribute;
|
||||
|
||||
@@ -58,7 +58,7 @@ public class BiFunctionConvertMain {
|
||||
return t.get(u);
|
||||
}, (Object u) -> {
|
||||
if (table != u) return null;
|
||||
return new EnFieldObject[]{new EnFieldObject("extcol1", 30), new EnFieldObject("extcol2", "扩展字段值")};
|
||||
return new EnFieldValue[]{new EnFieldValue("extcol1", 30), new EnFieldValue("extcol2", "扩展字段值")};
|
||||
});
|
||||
System.out.println(convert2.convertTo(table));
|
||||
//{"players":[{"cards":[11,12,13,14,15],"userid":1,"username":"玩家1"},{"cards":[21,22,23,24,25],"userid":2,"username":"玩家2"},{"cards":[31,32,33,34,35],"userid":3,"username":"玩家3"}],"tableid":100}
|
||||
|
||||
Reference in New Issue
Block a user