@@ -132,16 +132,16 @@ public Map<Object, Object> convertToEntityProperty(byte[] databaseValue) { |
132 | 132 | abstract Object convertToKey(String keyValue); |
133 | 133 |
|
134 | 134 | /** |
135 | | - * Returns the width in bytes stored in the private parentWidth field of FlexBuffers.Reference. |
| 135 | + * Returns true if the width in bytes stored in the private parentWidth field of FlexBuffers.Reference is 8. |
136 | 136 | * Note: FlexBuffers stores all items in a map/vector using the size of the widest item. However, |
137 | 137 | * an item's size is only as wide as needed, e.g. a 64-bit integer (Java Long, 8 bytes) will be |
138 | 138 | * reduced to 1 byte if it does not exceed its value range. |
139 | 139 | */ |
140 | | - private int getParentWidthInBytesOf(FlexBuffers.Reference reference) { |
| 140 | + protected boolean shouldRestoreAsLong(FlexBuffers.Reference reference) { |
141 | 141 | try { |
142 | 142 | Field parentWidthF = reference.getClass().getDeclaredField("parentWidth"); |
143 | 143 | parentWidthF.setAccessible(true); |
144 | | - return (int) parentWidthF.get(reference); |
| 144 | + return (int) parentWidthF.get(reference) == 8; |
145 | 145 | } catch (Exception e) { |
146 | 146 | // If thrown, it is likely the FlexBuffers API has changed and the above should be updated. |
147 | 147 | throw new RuntimeException("FlexMapConverter could not determine FlexBuffers integer bit width.", e); |
@@ -167,8 +167,7 @@ private Map<Object, Object> buildMap(FlexBuffers.Map map) { |
167 | 167 | } else if (value.isBoolean()) { |
168 | 168 | resultMap.put(key, value.asBoolean()); |
169 | 169 | } else if (value.isInt()) { |
170 | | - int parentWidthInBytes = getParentWidthInBytesOf(value); |
171 | | - if (parentWidthInBytes == 8) { |
| 170 | + if (shouldRestoreAsLong(value)) { |
172 | 171 | resultMap.put(key, value.asLong()); |
173 | 172 | } else { |
174 | 173 | resultMap.put(key, value.asInt()); |
@@ -192,7 +191,7 @@ private List<Object> buildList(FlexBuffers.Vector vector) { |
192 | 191 | List<Object> list = new ArrayList<>(itemCount); |
193 | 192 |
|
194 | 193 | // FlexBuffers uses the byte width of the biggest item to size all items, so only need to check the first. |
195 | | - Integer parentWidthInBytes = null; |
| 194 | + Boolean shouldRestoreAsLong = null; |
196 | 195 |
|
197 | 196 | for (int i = 0; i < itemCount; i++) { |
198 | 197 | FlexBuffers.Reference item = vector.get(i); |
@@ -205,10 +204,10 @@ private List<Object> buildList(FlexBuffers.Vector vector) { |
205 | 204 | } else if (item.isBoolean()) { |
206 | 205 | list.add(item.asBoolean()); |
207 | 206 | } else if (item.isInt()) { |
208 | | - if (parentWidthInBytes == null) { |
209 | | - parentWidthInBytes = getParentWidthInBytesOf(item); |
| 207 | + if (shouldRestoreAsLong == null) { |
| 208 | + shouldRestoreAsLong = shouldRestoreAsLong(item); |
210 | 209 | } |
211 | | - if (parentWidthInBytes == 8) { |
| 210 | + if (shouldRestoreAsLong) { |
212 | 211 | list.add(item.asLong()); |
213 | 212 | } else { |
214 | 213 | list.add(item.asInt()); |
|