I am trying to write code which can serialize javax.measure.unit.Unit instances into JSON. For this I am using the Jackson object mapper. The object mapper can't directly serialize Unit instances due to a self-reference, so instead I store a String representation of the Unit.
While serializing I do something like
String jsonString = serialize(unit.toString());
While deserializing I do:
String unitString = deserialize(jsonString);
Unit<?> unit = Unit.valueOf(unitString);
This works for most of the basic units, but not for something like say "NonSI.Byte.times(1024)". Essentially the following code throws a ParseException:
Unit.valueOf(NonSI.BYTE.times(1024).toString());
Does anyone know how to solve this?