mirror of
https://github.com/etesync/android
synced 2025-02-05 04:11:04 +00:00
abc15f01d8
I was trying to avoid it, and keep it as davdroid both for attribution, and making it easy to cherry-pick fixes from DAVdroid. However, it seems to be causing clashes with the davdroid app, although every piece of documentation claims otherwise.[1] At least it seems like cherry-picks can still be achieved using: git cherry-pick -s recursive -X find-renames=30 COMMIT 1. https://developer.android.com/studio/build/application-id.html (one such doc)
32 lines
1.2 KiB
Java
32 lines
1.2 KiB
Java
package com.etesync.syncadapter;
|
|
|
|
import android.util.Base64;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.GsonBuilder;
|
|
import com.google.gson.JsonDeserializationContext;
|
|
import com.google.gson.JsonDeserializer;
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonParseException;
|
|
import com.google.gson.JsonPrimitive;
|
|
import com.google.gson.JsonSerializationContext;
|
|
import com.google.gson.JsonSerializer;
|
|
|
|
import java.lang.reflect.Type;
|
|
|
|
public class GsonHelper {
|
|
public static final Gson gson = new GsonBuilder().registerTypeHierarchyAdapter(byte[].class,
|
|
new ByteArrayToBase64TypeAdapter()).create();
|
|
|
|
// Using Android's base64 libraries. This can be replaced with any base64 library.
|
|
private static class ByteArrayToBase64TypeAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> {
|
|
public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
|
return Base64.decode(json.getAsString(), Base64.NO_WRAP);
|
|
}
|
|
|
|
public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContext context) {
|
|
return new JsonPrimitive(Base64.encodeToString(src, Base64.NO_WRAP));
|
|
}
|
|
}
|
|
}
|