This commit is contained in:
Redkale
2018-07-15 23:42:28 +08:00
parent c2c8f700a2
commit 9bd1e0c97b
7 changed files with 20 additions and 2 deletions

View File

@@ -139,6 +139,8 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
public abstract boolean isReversible(); //是否可逆的
public abstract boolean isFieldSort(); //当ConvertColumn.index相同时是否按字段名称排序
public abstract ConvertFactory createChild();
public abstract ConvertFactory createChild(boolean tiny);

View File

@@ -24,6 +24,8 @@ public final class DeMember<R extends Reader, T, F> implements Comparable<DeMemb
protected int index;
protected boolean fieldSort;
protected final Attribute<T, F> attribute;
protected Decodeable<R, F> decoder;
@@ -78,7 +80,7 @@ public final class DeMember<R extends Reader, T, F> implements Comparable<DeMemb
public final int compareTo(DeMember<R, T, F> o) {
if (o == null) return -1;
if (this.index != o.index) return (this.index == 0 ? Integer.MAX_VALUE : this.index) - (o.index == 0 ? Integer.MAX_VALUE : o.index);
return this.attribute.field().compareTo(o.attribute.field());
return fieldSort ? this.attribute.field().compareTo(o.attribute.field()) : 0;
}
@Override

View File

@@ -33,6 +33,8 @@ public final class EnMember<W extends Writer, T, F> implements Comparable<EnMemb
protected int index;
protected boolean fieldSort;
public EnMember(Attribute<T, F> attribute, Encodeable<W, F> encoder) {
this.attribute = attribute;
this.encoder = encoder;
@@ -71,7 +73,7 @@ public final class EnMember<W extends Writer, T, F> implements Comparable<EnMemb
public final int compareTo(EnMember<W, T, F> o) {
if (o == null) return -1;
if (this.index != o.index) return (this.index == 0 ? Integer.MAX_VALUE : this.index) - (o.index == 0 ? Integer.MAX_VALUE : o.index);
return this.attribute.field().compareTo(o.attribute.field());
return fieldSort ? this.attribute.field().compareTo(o.attribute.field()) : 0;
}
@Override

View File

@@ -97,6 +97,7 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
if (ref != null && ref.ignore()) continue;
Type t = TypeToken.createClassType(TypeToken.getGenericType(field.getGenericType(), this.type), this.type);
DeMember member = new DeMember(ObjectEncoder.createAttribute(factory, clazz, field, null, null), factory.loadDecoder(t));
member.fieldSort = factory.isFieldSort();
if (ref != null) member.index = ref.getIndex();
list.add(member);
}

View File

@@ -104,6 +104,7 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
if (ref != null && ref.ignore()) continue;
Type t = TypeToken.createClassType(TypeToken.getGenericType(method.getGenericReturnType(), this.type), this.type);
EnMember member = new EnMember(createAttribute(factory, clazz, null, method, null), factory.loadEncoder(t));
member.fieldSort = factory.isFieldSort();
if (ref != null) member.index = ref.getIndex();
list.add(member);
}

View File

@@ -84,4 +84,9 @@ public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
return true;
}
@Override
public boolean isFieldSort() {
return true;
}
}

View File

@@ -85,4 +85,9 @@ public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
public boolean isReversible() {
return false;
}
@Override
public boolean isFieldSort() {
return true;
}
}