use of com.palantir.atlasdb.persist.api.Persister in project atlasdb by palantir.
the class ColumnValueDescription method persistJsonToBytes.
@SuppressWarnings("unchecked")
public byte[] persistJsonToBytes(ClassLoader classLoader, String str) throws ParseException {
final byte[] bytes;
if (format == Format.PERSISTABLE) {
throw new SafeIllegalArgumentException("Tried to pass json into a persistable type.");
} else if (format == Format.PERSISTER) {
Persister<?> persister = getPersister();
if (JsonNode.class == persister.getPersistingClassType()) {
try {
JsonNode jsonNode = new ObjectMapper().readValue(str, JsonNode.class);
return ((Persister<JsonNode>) persister).persistToBytes(jsonNode);
} catch (IOException e) {
throw Throwables.throwUncheckedException(e);
}
} else {
throw new SafeIllegalArgumentException("Tried to write json to a Persister that isn't for JsonNode.");
}
} else if (format == Format.PROTO) {
Message.Builder builder = createBuilder(classLoader);
// This will have issues with base64 blobs
JsonFormat.merge(str, builder);
bytes = builder.build().toByteArray();
} else {
bytes = type.convertFromString(str);
}
return CompressionUtils.compress(bytes, compression);
}
Aggregations