-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialize null values in ChangesetEntry (#135)
* cleanup * Serialize null values in ChangesetEntry
- Loading branch information
1 parent
fb264e2
commit b4eaf19
Showing
7 changed files
with
48 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/main/java/io/castle/client/internal/backend/OkRestApiBackend.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/io/castle/client/internal/json/ChangesetEntryTypeAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.castle.client.internal.json; | ||
|
||
import com.google.gson.reflect.TypeToken; | ||
import com.google.gson.*; | ||
import com.google.gson.stream.JsonReader; | ||
import com.google.gson.stream.JsonWriter; | ||
|
||
import io.castle.client.model.generated.ChangesetEntry; | ||
|
||
import java.io.IOException; | ||
|
||
public class ChangesetEntryTypeAdapter extends TypeAdapter<ChangesetEntry> { | ||
static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() { | ||
@SuppressWarnings("unchecked") | ||
@Override | ||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { | ||
if (type.getRawType() != ChangesetEntry.class) { | ||
return null; | ||
} | ||
TypeAdapter<ChangesetEntry> delegate = (TypeAdapter<ChangesetEntry>) gson.getDelegateAdapter(this, type); | ||
return (TypeAdapter<T>) new ChangesetEntryTypeAdapter(delegate); | ||
} | ||
}; | ||
|
||
private final TypeAdapter<ChangesetEntry> delegate; | ||
|
||
ChangesetEntryTypeAdapter(TypeAdapter<ChangesetEntry> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override public void write(JsonWriter out, ChangesetEntry value) throws IOException { | ||
boolean serializeNulls = out.getSerializeNulls(); | ||
out.setSerializeNulls(true); | ||
try { | ||
delegate.write(out, value); | ||
} finally { | ||
out.setSerializeNulls(serializeNulls); | ||
} | ||
} | ||
|
||
@Override public ChangesetEntry read(JsonReader in) throws IOException { | ||
return delegate.read(in); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters