updated JsonDeserializer example (#2192)

* fixed json deserializer example

* correcting the json

* updated per review

* updated per review

* updated per review
This commit is contained in:
Deepti M 2022-09-12 13:14:05 -04:00 committed by GitHub
parent 847d7f6638
commit a733150cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -48,11 +48,13 @@ import java.lang.reflect.Type;
* deserializer:</p>
*
* <pre>
* class IdDeserializer implements JsonDeserializer&lt;Id&gt;() {
* class IdDeserializer implements JsonDeserializer&lt;Id&gt; {
* public Id deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
* throws JsonParseException {
* return new Id((Class)typeOfT, id.getValue());
* long idValue = json.getAsJsonPrimitive().getAsLong();
* return new Id((Class) typeOfT, idValue);
* }
* }
* </pre>
*
* <p>You will also need to register {@code IdDeserializer} with Gson as follows:</p>

View File

@ -48,7 +48,7 @@ import java.lang.reflect.Type;
* serializer:</p>
*
* <pre>
* class IdSerializer implements JsonSerializer&lt;Id&gt;() {
* class IdSerializer implements JsonSerializer&lt;Id&gt; {
* public JsonElement serialize(Id id, Type typeOfId, JsonSerializationContext context) {
* return new JsonPrimitive(id.getValue());
* }