diff --git a/gson/src/main/java/com/google/gson/JsonDeserializer.java b/gson/src/main/java/com/google/gson/JsonDeserializer.java index 46550edf..6462d45c 100644 --- a/gson/src/main/java/com/google/gson/JsonDeserializer.java +++ b/gson/src/main/java/com/google/gson/JsonDeserializer.java @@ -48,11 +48,13 @@ import java.lang.reflect.Type; * deserializer:
* *- * class IdDeserializer implements JsonDeserializer<Id>() { + * class IdDeserializer implements JsonDeserializer<Id> { * 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); * } + * } ** *
You will also need to register {@code IdDeserializer} with Gson as follows:
diff --git a/gson/src/main/java/com/google/gson/JsonSerializer.java b/gson/src/main/java/com/google/gson/JsonSerializer.java index 9b3e1ed5..2bdb8fb2 100644 --- a/gson/src/main/java/com/google/gson/JsonSerializer.java +++ b/gson/src/main/java/com/google/gson/JsonSerializer.java @@ -48,7 +48,7 @@ import java.lang.reflect.Type; * serializer: * *- * class IdSerializer implements JsonSerializer<Id>() { + * class IdSerializer implements JsonSerializer<Id> { * public JsonElement serialize(Id id, Type typeOfId, JsonSerializationContext context) { * return new JsonPrimitive(id.getValue()); * }