summaryrefslogtreecommitdiffstats
path: root/src/net/gcdc/asn1/uper
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2020-10-29 12:44:07 +0100
committerCGantert345 <57003061+CGantert345@users.noreply.github.com>2020-10-29 12:44:07 +0100
commitca0191d050b3dac6e65815ad5662ed8e796ef9d9 (patch)
tree6690d0d9d771f3033e4106d3b22d025602571cb2 /src/net/gcdc/asn1/uper
parentspecification added, test fixed (diff)
downloadUIC-barcode-ca0191d050b3dac6e65815ad5662ed8e796ef9d9.tar
UIC-barcode-ca0191d050b3dac6e65815ad5662ed8e796ef9d9.tar.gz
UIC-barcode-ca0191d050b3dac6e65815ad5662ed8e796ef9d9.tar.bz2
UIC-barcode-ca0191d050b3dac6e65815ad5662ed8e796ef9d9.tar.lz
UIC-barcode-ca0191d050b3dac6e65815ad5662ed8e796ef9d9.tar.xz
UIC-barcode-ca0191d050b3dac6e65815ad5662ed8e796ef9d9.tar.zst
UIC-barcode-ca0191d050b3dac6e65815ad5662ed8e796ef9d9.zip
Diffstat (limited to '')
-rw-r--r--src/net/gcdc/asn1/uper/UperEncoder.java29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/net/gcdc/asn1/uper/UperEncoder.java b/src/net/gcdc/asn1/uper/UperEncoder.java
index f9c2f2a..30aa82b 100644
--- a/src/net/gcdc/asn1/uper/UperEncoder.java
+++ b/src/net/gcdc/asn1/uper/UperEncoder.java
@@ -7,6 +7,8 @@ import java.lang.reflect.InvocationTargetException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -17,6 +19,7 @@ import logger.LoggerFactory;
import net.gcdc.asn1.datatypes.Asn1Default;
import net.gcdc.asn1.datatypes.Asn1Optional;
+import net.gcdc.asn1.datatypes.FieldOrder;
import net.gcdc.asn1.datatypes.HasExtensionMarker;
import net.gcdc.asn1.datatypes.IntRange;
import net.gcdc.asn1.datatypes.IsExtension;
@@ -405,7 +408,31 @@ public final class UperEncoder {
Map<Field, Boolean> originalAccess = new HashMap<>();
Asn1ContainerFieldSorter(Class<?> type) {
- for (Field f : type.getDeclaredFields()) {
+
+ /*
+ *
+ * sorting of the fields added to compensate the error
+ * in the java SDK on android where getDeclaredFields does
+ * not return the fields in the order of the class definition
+ *
+ */
+ List<Field> fields = Arrays.asList(type.getDeclaredFields());
+ Collections.sort(fields, new Comparator<Field>() {
+ @Override
+ public int compare(Field o1, Field o2) {
+ FieldOrder ao1 = o1.getAnnotation(FieldOrder.class);
+ FieldOrder ao2 = o2.getAnnotation(FieldOrder.class);
+ int order1 = ao1 == null ? Integer.MAX_VALUE : ao1.order();
+ int order2 = ao2 == null ? Integer.MAX_VALUE : ao2.order();
+ if (order1 == Integer.MAX_VALUE || order2 == Integer.MAX_VALUE || order1 < 0 || order2 < 0 || order1 == order2) {
+ logger.debug(String.format("field order error for %s",type.getSimpleName()));
+ }
+ return Integer.compare(order1, order2);
+ }
+ });
+
+
+ for (Field f : fields) {
if (isTestInstrumentation(f) || isNonAsn1Field(f) ) {
continue;
}