Skip to content

Commit 1927a93

Browse files
committed
Add support for java date util in java object serialization
1 parent 310dc04 commit 1927a93

File tree

5 files changed

+42
-38
lines changed

5 files changed

+42
-38
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
"gzip-js": "^0.3.2",
235235
"html-entities": "^2.3.2",
236236
"html-react-parser": "^1.2.4",
237-
"java-object-serialization": "^0.1.1",
237+
"java-object-serialization": "^0.1.2",
238238
"js-yaml": "^4.1.0",
239239
"json-bigint": "^1.0.0",
240240
"jsonpath": "^1.1.1",

redisinsight/ui/src/utils/formatters/bufferFormatters.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ObjectInputStream } from 'java-object-serialization'
33
import { TextDecoder, TextEncoder } from 'text-encoding'
44
import { Buffer } from 'buffer'
55
import { KeyValueFormat } from 'uiSrc/constants'
6+
import JavaDate from './java-date'
67
// eslint-disable-next-line import/order
78
import {
89
RedisResponseBuffer,
@@ -12,6 +13,8 @@ import {
1213
} from 'uiSrc/slices/interfaces'
1314
import { Nullable } from '../types'
1415

16+
ObjectInputStream.RegisterObjectClass(JavaDate, 'java.util.Date', '7523967970034938905')
17+
1518
const decoder = new TextDecoder('utf-8')
1619
const encoder = new TextEncoder()
1720

@@ -171,6 +174,10 @@ const bufferToJava = (reply: RedisResponseBuffer) => {
171174
return decoded
172175
}
173176

177+
if (decoded instanceof Date) {
178+
return decoded
179+
}
180+
174181
const { fields } = decoded
175182
const fieldsArray = Array.from(fields, ([key, value]) => ({ [key]: value }))
176183
return { ...decoded, fields: fieldsArray }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ObjectInputStream, JavaSerializable } from 'java-object-serialization'
2+
3+
export default class JavaDate implements JavaSerializable {
4+
time: bigint = 0n
5+
6+
readObject(stream: ObjectInputStream): void {
7+
this.time = stream.readLong()
8+
}
9+
10+
readResolve(): any {
11+
return new Date(Number(this.time))
12+
}
13+
}

redisinsight/ui/src/utils/tests/formatters/bufferFormatters.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { input } from '@testing-library/user-event/dist/types/event'
22
import { RedisResponseBufferType } from 'uiSrc/slices/interfaces'
3+
import JavaDate from 'uiSrc/utils/formatters/java-date'
34
import {
45
bufferToString,
56
anyToBuffer,
@@ -16,6 +17,12 @@ import {
1617
bufferToUint8Array,
1718
} from 'uiSrc/utils'
1819

20+
try {
21+
// Register JavaDate class for deserialization
22+
ObjectInputStream.RegisterObjectClass(JavaDate, 'java.util.Date', '7523967970034938905')
23+
// eslint-disable-next-line no-empty
24+
} catch (e) {}
25+
1926
const defaultValues = [
2027
{ unicode: 'test', ascii: 'test', hex: '74657374', uint8Array: [116, 101, 115, 116], binary: '01110100011001010111001101110100' },
2128
{ unicode: 'test test', ascii: 'test test', hex: '746573742074657374', uint8Array: [116, 101, 115, 116, 32, 116, 101, 115, 116], binary: '011101000110010101110011011101000010000001110100011001010111001101110100' },
@@ -134,6 +141,7 @@ describe('binaryToBuffer', () => {
134141
const javaValues = [
135142
{ uint8Array: [172, 237, 0, 5, 115, 114, 0, 8, 69, 109, 112, 108, 111, 121, 101, 101, 2, 94, 116, 52, 103, 198, 18, 60, 2, 0, 3, 73, 0, 6, 110, 117, 109, 98, 101, 114, 76, 0, 7, 97, 100, 100, 114, 101, 115, 115, 116, 0, 18, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 83, 116, 114, 105, 110, 103, 59, 76, 0, 4, 110, 97, 109, 101, 113, 0, 126, 0, 1, 120, 112, 0, 0, 0, 101, 116, 0, 25, 80, 104, 111, 107, 107, 97, 32, 75, 117, 97, 110, 44, 32, 65, 109, 98, 101, 104, 116, 97, 32, 80, 101, 101, 114, 116, 0, 9, 82, 101, 121, 97, 110, 32, 65, 108, 105], value: { annotations: [], className: 'Employee', fields: [{ number: 101 }, { address: 'Phokka Kuan, Ambehta Peer' }, { name: 'Reyan Ali' }], serialVersionUid: 170701604314812988n } },
136143
{ uint8Array: [172, 237, 0, 5, 115, 114, 0, 32, 115, 101, 114, 105, 97, 108, 105, 122, 97, 116, 105, 111, 110, 68, 101, 109, 111, 46, 65, 110, 110, 111, 116, 97, 116, 105, 111, 110, 84, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 1, 73, 0, 6, 110, 117, 109, 98, 101, 114, 120, 112, 0, 0, 0, 90], value: { annotations: [], className: 'serializationDemo.AnnotationTest', fields: [{ number: 90 }], serialVersionUid: 2n } },
144+
{ uint8Array: [ 172, 237, 0, 5, 115, 114, 0, 14, 106, 97, 118, 97, 46, 117, 116, 105, 108, 46, 68, 97, 116, 101, 104, 106, 129, 1, 75, 89, 116, 25, 3, 0, 0, 120, 112, 119, 8, 0, 0, 1, 146, 226, 121, 165, 136, 120, ], value: new Date(Number(1730376476040n)) },
137145
]
138146

139147
const getBufferToJavaTests = javaValues.map(({ uint8Array, value }) =>
@@ -150,3 +158,4 @@ describe('bufferToUint8Array', () => {
150158
expect(bufferToUint8Array(anyToBuffer(uint8Array))).toEqual(new Uint8Array(uint8Array))
151159
})
152160
})
161+

yarn.lock

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8284,12 +8284,12 @@ jake@^10.8.5:
82848284
filelist "^1.0.1"
82858285
minimatch "^3.0.4"
82868286

8287-
java-object-serialization@^0.1.1:
8288-
version "0.1.1"
8289-
resolved "https://registry.yarnpkg.com/java-object-serialization/-/java-object-serialization-0.1.1.tgz#b20f34a619df3ce4b58980d7d9893048a696a0bd"
8290-
integrity sha512-m1bd/kPwNjbrMrIITzMGWoXiSU5fzUg6IdzGDrmGNPahNQ5YVzY9dv5qQzAcRC7oy0C0CwDseatdeI6SKO8MLA==
8287+
java-object-serialization@^0.1.2:
8288+
version "0.1.2"
8289+
resolved "https://registry.yarnpkg.com/java-object-serialization/-/java-object-serialization-0.1.2.tgz#229ee4b70ea89e72206e32a826afacd09d9badfd"
8290+
integrity sha512-l0V2a/E7r6ScqG+ne09KR7G1npbiVdDf3Vdk6fcn8jy5TQiTTOQbDg9OfBriv2NmnCxcm4NmFW2dAD9QaN/htw==
82918291
dependencies:
8292-
tslib "^2.1.0"
8292+
tslib "^2.8.0"
82938293

82948294
jest-changed-files@^29.7.0:
82958295
version "29.7.0"
@@ -12624,16 +12624,7 @@ string-length@^4.0.1:
1262412624
char-regex "^1.0.2"
1262512625
strip-ansi "^6.0.0"
1262612626

12627-
"string-width-cjs@npm:string-width@^4.2.0":
12628-
version "4.2.3"
12629-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
12630-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
12631-
dependencies:
12632-
emoji-regex "^8.0.0"
12633-
is-fullwidth-code-point "^3.0.0"
12634-
strip-ansi "^6.0.1"
12635-
12636-
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
12627+
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
1263712628
version "4.2.3"
1263812629
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1263912630
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -12738,14 +12729,7 @@ stringify-object@^3.3.0:
1273812729
is-obj "^1.0.1"
1273912730
is-regexp "^1.0.0"
1274012731

12741-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
12742-
version "6.0.1"
12743-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
12744-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
12745-
dependencies:
12746-
ansi-regex "^5.0.1"
12747-
12748-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
12732+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1274912733
version "6.0.1"
1275012734
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1275112735
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -13218,10 +13202,10 @@ tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.3:
1321813202
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
1321913203
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
1322013204

13221-
tslib@^2.0.0, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.1:
13222-
version "2.5.0"
13223-
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
13224-
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==
13205+
tslib@^2.0.0, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.1, tslib@^2.8.0:
13206+
version "2.8.0"
13207+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.0.tgz#d124c86c3c05a40a91e6fdea4021bd31d377971b"
13208+
integrity sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==
1322513209

1322613210
tsutils@^3.21.0:
1322713211
version "3.21.0"
@@ -14090,7 +14074,7 @@ [email protected], word-wrap@^1.2.3, word-wrap@~1.2.3:
1409014074
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.4.tgz#cb4b50ec9aca570abd1f52f33cd45b6c61739a9f"
1409114075
integrity sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==
1409214076

14093-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
14077+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1409414078
version "7.0.0"
1409514079
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1409614080
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -14108,15 +14092,6 @@ wrap-ansi@^6.2.0:
1410814092
string-width "^4.1.0"
1410914093
strip-ansi "^6.0.0"
1411014094

14111-
wrap-ansi@^7.0.0:
14112-
version "7.0.0"
14113-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
14114-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
14115-
dependencies:
14116-
ansi-styles "^4.0.0"
14117-
string-width "^4.1.0"
14118-
strip-ansi "^6.0.0"
14119-
1412014095
wrap-ansi@^8.1.0:
1412114096
version "8.1.0"
1412214097
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)