Skip to content

Instantly share code, notes, and snippets.

Christian Melchior cmelchior

Block or report user

Report or block cmelchior

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cmelchior
cmelchior / CustomTypeAdapter.java
Created Apr 9, 2015
Realm, GSON and primitive JSON arrays
View CustomTypeAdapter.java
// Make a custom Gson instance, with a custom TypeAdapter for each wrapper object.
// In this instance we only have RealmList<RealmInt> as a a wrapper for RealmList<Integer>
Type token = new TypeToken<RealmList<RealmInt>>(){}.getType();
Gson gson = new GsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getDeclaringClass().equals(RealmObject.class);
}
@cmelchior
cmelchior / BarListParcelConverter.java
Last active Aug 29, 2019
Using Parceler 1.0.3 with Realm
View BarListParcelConverter.java
// Specific class for a RealmList<Bar> field
public class BarListParcelConverter extends RealmListParcelConverter<Bar> {
@Override
public void itemToParcel(Bar input, Parcel parcel) {
parcel.writeParcelable(Parcels.wrap(input), 0);
}
@Override
public Bar itemFromParcel(Parcel parcel) {
@cmelchior
cmelchior / SerializeToJson.java
Last active Oct 13, 2019
Serialize Realm objects to JSON using GSON
View SerializeToJson.java
// GSON can parse the data.
//
// Deserialization:
// Note there is a bug in GSON 2.3.1 that can cause it to StackOverflow when working with RealmObjects.
// To work around this, use the ExclusionStrategy below or downgrade to 1.7.1
// See more here: https://code.google.com/p/google-gson/issues/detail?id=440
//
// Serialization:
// <Type>RealmProxy objects are created by the Realm annotation processor. They are used to control
// access to the actual data instead of storing them in fields and it is therefore them we need to register a
You can’t perform that action at this time.