Initialize ByteSize object from JSON object according to order of precedence i.e from 'b' -> 'PB', where 'b' has higher precedence to 'KB' and 'MB' has higher precedence to 'GB' and so on.
Source
ByteSize.fromJson(Map<String, Object> entityMap) { ByteSize bs; try { if (entityMap.containsKey(_BitSymbol)) { bs = FromBits(entityMap[_BitSymbol] is String ? int.parse(entityMap[_BitSymbol]) : entityMap[_BitSymbol]); } else if (entityMap.containsKey(_ByteSymbol)) { bs = FromBytes(entityMap[_ByteSymbol] is String ? num.parse(entityMap[_ByteSymbol]) : entityMap[_ByteSymbol]); } else if (entityMap.containsKey(_KiloByteSymbol)) { bs = FromKiloBytes(entityMap[_KiloByteSymbol] is String ? num.parse(entityMap[_KiloByteSymbol]) : entityMap[_KiloByteSymbol]); } else if (entityMap.containsKey(_MegaByteSymbol)) { bs = FromMegaBytes(entityMap[_MegaByteSymbol] is String ? num.parse(entityMap[_MegaByteSymbol]) : entityMap[_MegaByteSymbol]); } else if (entityMap.containsKey(_GigaByteSymbol)) { bs = FromGigaBytes(entityMap[_GigaByteSymbol] is String ? num.parse(entityMap[_GigaByteSymbol]) : entityMap[_GigaByteSymbol]); } else if (entityMap.containsKey(_TeraByteSymbol)) { bs = FromTeraBytes(entityMap[_TeraByteSymbol] is String ? num.parse(entityMap[_TeraByteSymbol]) : entityMap[_TeraByteSymbol]); } else if (entityMap.containsKey(_PetaByteSymbol)) { bs = FromPetaBytes(entityMap[_PetaByteSymbol] is String ? num.parse(entityMap[_PetaByteSymbol]) : entityMap[_PetaByteSymbol]); } else { throw Exception; } _clone(bs); } on Exception { throw FormatException('Json object not in correct format'); } }