-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLAT-3808] Add type adapter for OneOfWebhookEventSceneIncludedData (#49
- Loading branch information
Showing
4 changed files
with
53 additions
and
5 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
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ plugins { | |
} | ||
|
||
group = 'com.vertexvis' | ||
version = '0.7.5' | ||
version = '0.7.6' | ||
|
||
repositories { | ||
mavenCentral() | ||
|
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
...java/com/vertexvis/model/serialization/OneOfWebhookEventSceneIncludedDataTypeAdapter.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 com.vertexvis.model.serialization; | ||
|
||
import com.google.gson.*; | ||
import com.google.gson.reflect.TypeToken; | ||
import com.google.gson.stream.JsonReader; | ||
import com.google.gson.stream.JsonWriter; | ||
import com.vertexvis.model.*; | ||
|
||
import java.io.IOException; | ||
import java.util.function.Supplier; | ||
|
||
public class OneOfWebhookEventSceneIncludedDataTypeAdapter extends TypeAdapter<OneOfWebhookEventSceneIncludedData> { | ||
private Supplier<Gson> gsonSupplier; | ||
|
||
public OneOfWebhookEventSceneIncludedDataTypeAdapter(Supplier<Gson> gsonSupplier) { | ||
this.gsonSupplier = gsonSupplier; | ||
} | ||
|
||
@Override | ||
public void write(JsonWriter out, OneOfWebhookEventSceneIncludedData value) throws IOException { | ||
TypeAdapter<JsonElement> jsonAdapter = gsonSupplier.get().getAdapter(JsonElement.class); | ||
TypeAdapter<WebhookEventSceneIncludedData> sceneIncludedDataTypeAdapter = gsonSupplier.get().getAdapter(TypeToken.get(WebhookEventSceneIncludedData.class)); | ||
|
||
if (value.getData() instanceof WebhookEventSceneIncludedData) { | ||
jsonAdapter.write(out, sceneIncludedDataTypeAdapter.toJsonTree(value.getSceneIncludedData())); | ||
} | ||
} | ||
|
||
@Override | ||
public OneOfWebhookEventSceneIncludedData read(JsonReader in) throws IOException { | ||
TypeAdapter<JsonElement> jsonAdapter = gsonSupplier.get().getAdapter(JsonElement.class); | ||
TypeAdapter<WebhookEventSceneIncludedData> sceneIncludedDataTypeAdapter = gsonSupplier.get().getAdapter(TypeToken.get(WebhookEventSceneIncludedData.class)); | ||
|
||
JsonObject json = jsonAdapter.read(in).getAsJsonObject(); | ||
String type = json.get("type").getAsString(); | ||
|
||
switch (type) { | ||
case "scene": | ||
return new OneOfWebhookEventSceneIncludedData(sceneIncludedDataTypeAdapter.fromJsonTree(json)); | ||
default: | ||
throw new IOException("JSON deserializer not implemented for type " + type); | ||
} | ||
} | ||
} |