I'm writing a JavaFX program, which should have user management and DB back-end. My data-model classes all use JavaFX-style properties (for easier UI integration, see e.g. this ).
But now I have come upon a technical problem my User
class needs to have byte[]
fields - namely these for password hash and salt.
Since MessageDigest
and similar Java services expect byte[]
, the obvious solution of using ObjectProperty<Byte[]>
becomes cumbersome, as with every usage of the fields I will have to create a new byte[]
and copy the values.
For example:
SimpleObjectProperty<Byte[]> toHash = new SimpleObjectProperty<>();
MessageDigest md;
// initialize message digest and Byte[] property here...
// Does not compile - can't convert Byte[] to byte[]
// md.update(toHash.get());
// What does work:
byte[] bytes = new byte[toHash.get().length];
for (int i=0; i<bytes.length; i++)
bytes[i] = toHash.get()[i];
md.update(bytes);
So my question is - is there a simple solution that will allow me to have JavaFX-style properties which I can get and set with primitive arrays?
Is implementing something like PrimitiveByteArrayProperty
a sound choice, or even a feasible one? Do such solutions exist already?
Edit: I have apparently ignored the trivial solution of using ObjectProperty<byte[]>
, having thought Java disallows generics of primitive arrays.