Skip to content

Commit a733150

Browse files
updated JsonDeserializer example (#2192)
* fixed json deserializer example * correcting the json * updated per review * updated per review * updated per review
1 parent 847d7f6 commit a733150

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

gson/src/main/java/com/google/gson/JsonDeserializer.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@
4848
* deserializer:</p>
4949
*
5050
* <pre>
51-
* class IdDeserializer implements JsonDeserializer&lt;Id&gt;() {
51+
* class IdDeserializer implements JsonDeserializer&lt;Id&gt; {
5252
* public Id deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
5353
* throws JsonParseException {
54-
* return new Id((Class)typeOfT, id.getValue());
54+
* long idValue = json.getAsJsonPrimitive().getAsLong();
55+
* return new Id((Class) typeOfT, idValue);
5556
* }
57+
* }
5658
* </pre>
5759
*
5860
* <p>You will also need to register {@code IdDeserializer} with Gson as follows:</p>

gson/src/main/java/com/google/gson/JsonSerializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* serializer:</p>
4949
*
5050
* <pre>
51-
* class IdSerializer implements JsonSerializer&lt;Id&gt;() {
51+
* class IdSerializer implements JsonSerializer&lt;Id&gt; {
5252
* public JsonElement serialize(Id id, Type typeOfId, JsonSerializationContext context) {
5353
* return new JsonPrimitive(id.getValue());
5454
* }

0 commit comments

Comments
 (0)