This commit is contained in:
@@ -36,7 +36,7 @@ public abstract class Convert<R extends Reader, W extends Writer> {
|
|||||||
return writer;
|
return writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <S extends W> S fieldFunc(S writer, BiFunction<Attribute, Object, Object> objFieldFunc, Function<Object, EnFieldValue[]> objExtFunc) {
|
protected <S extends W> S fieldFunc(S writer, BiFunction<Attribute, Object, Object> objFieldFunc, Function<Object, ConvertField[]> objExtFunc) {
|
||||||
writer.objFieldFunc = objFieldFunc;
|
writer.objFieldFunc = objFieldFunc;
|
||||||
writer.objExtFunc = objExtFunc;
|
writer.objExtFunc = objExtFunc;
|
||||||
return writer;
|
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);
|
||||||
|
|
||||||
public abstract Convert<R, W> newConvert(final BiFunction<Attribute, Object, Object> objFieldFunc, Function<Object, EnFieldValue[]> objExtFunc);
|
public abstract Convert<R, W> newConvert(final BiFunction<Attribute, Object, Object> objFieldFunc, Function<Object, ConvertField[]> objExtFunc);
|
||||||
|
|
||||||
public abstract boolean isBinary();
|
public abstract boolean isBinary();
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import org.redkale.convert.json.JsonConvert;
|
|||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
public class EnFieldValue implements Serializable {
|
public class ConvertField implements Serializable {
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
@@ -27,38 +27,38 @@ public class EnFieldValue implements Serializable {
|
|||||||
|
|
||||||
protected Object value;
|
protected Object value;
|
||||||
|
|
||||||
public EnFieldValue() {
|
public ConvertField() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnFieldValue(String name, Object value) {
|
public ConvertField(String name, Object value) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnFieldValue(String name, int position, Object value) {
|
public ConvertField(String name, int position, Object value) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnFieldValue(String name, Type type, Object value) {
|
public ConvertField(String name, Type type, Object value) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnFieldValue(String name, Type type, int position, Object value) {
|
public ConvertField(String name, Type type, int position, Object value) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnFieldValue[] ofArray(Object... items) {
|
public static ConvertField[] ofArray(Object... items) {
|
||||||
int len = items.length / 2;
|
int len = items.length / 2;
|
||||||
EnFieldValue[] rs = new EnFieldValue[len];
|
ConvertField[] rs = new ConvertField[len];
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
rs[i] = new EnFieldValue(items[i * 2].toString(), items[i * 2 + 1]);
|
rs[i] = new ConvertField(items[i * 2].toString(), items[i * 2 + 1]);
|
||||||
}
|
}
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
@@ -170,10 +170,10 @@ public class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T> {
|
|||||||
out.writeObjectField(member, value);
|
out.writeObjectField(member, value);
|
||||||
}
|
}
|
||||||
if (out.objExtFunc != null) {
|
if (out.objExtFunc != null) {
|
||||||
EnFieldValue[] extFields = out.objExtFunc.apply(value);
|
ConvertField[] extFields = out.objExtFunc.apply(value);
|
||||||
if (extFields != null) {
|
if (extFields != null) {
|
||||||
Encodeable<W, ?> anyEncoder = factory.getAnyEncoder();
|
Encodeable<W, ?> anyEncoder = factory.getAnyEncoder();
|
||||||
for (EnFieldValue en : extFields) {
|
for (ConvertField en : extFields) {
|
||||||
if (en == null) continue;
|
if (en == null) continue;
|
||||||
maxPosition++;
|
maxPosition++;
|
||||||
out.writeObjectField(en.getName(), en.getType(), Math.max(en.getPosition(), maxPosition), anyEncoder, en.getValue());
|
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 BiFunction<Attribute, Object, Object> objFieldFunc;
|
||||||
|
|
||||||
//对某个对象进行动态扩展字段值处理
|
//对某个对象进行动态扩展字段值处理
|
||||||
protected Function<Object, EnFieldValue[]> objExtFunc;
|
protected Function<Object, ConvertField[]> objExtFunc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置specify
|
* 设置specify
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BsonConvert newConvert(final BiFunction<Attribute, Object, Object> fieldFunc, Function<Object, EnFieldValue[]> objExtFunc) {
|
public BsonConvert newConvert(final BiFunction<Attribute, Object, Object> fieldFunc, Function<Object, ConvertField[]> objExtFunc) {
|
||||||
return new BsonConvert(getFactory(), tiny) {
|
return new BsonConvert(getFactory(), tiny) {
|
||||||
@Override
|
@Override
|
||||||
protected <S extends BsonWriter> S configWrite(S writer) {
|
protected <S extends BsonWriter> S configWrite(S writer) {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class JsonConvert extends TextConvert<JsonReader, JsonWriter> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonConvert newConvert(final BiFunction<Attribute, Object, Object> fieldFunc, Function<Object, EnFieldValue[]> objExtFunc) {
|
public JsonConvert newConvert(final BiFunction<Attribute, Object, Object> fieldFunc, Function<Object, ConvertField[]> objExtFunc) {
|
||||||
return new JsonConvert(getFactory(), tiny) {
|
return new JsonConvert(getFactory(), tiny) {
|
||||||
@Override
|
@Override
|
||||||
protected <S extends JsonWriter> S configWrite(S writer) {
|
protected <S extends JsonWriter> S configWrite(S writer) {
|
||||||
|
|||||||
Reference in New Issue
Block a user