Deserializing JSON object to string field with GSON
<p>I have a POJO with a String field that is already serialized JSON. Performance is key here, so I want to avoid parsing it and then re-serializing it.</p>

<pre><code>public class SomeObject {
    String someString = "";
    String jsonString = "{\"one\":4, \"two\":\"hello\"}";
    long someLong = 4;
}
</code></pre>

<p>Currently GSON serialises it like so:</p>

<p><code>{ "someString":"", "jsonString":"{\"one\":4, \"two\":\"hello\"}", "someLong":4 }</code></p>

<p>I wrote a JsonSerializer/Deserializer in hopes of using the @JsonAdapter annotation, but it only supports TypeAdapter or TypeAdapterFactory.</p>

<pre><code>public class JsonStringTypeAdapter implements JsonSerializer&lt;String&gt;, JsonDeserializer&lt;String&gt; {

    @Override
    public JsonElement serialize(String t, Type type, JsonSerializationContext jsc) {
        return new JsonParser().parse(t).getAsJsonObject();
    }

    @Override
    public String deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException {
        return je.getAsString();
    }

    @Override
    public void write(JsonWriter writer, String t) throws IOException {
        writer.jsonValue(t);
    }

}
</code></pre>

<p>So I wrote the following simple TypeAdapter that works perfectly for serialisation, but I can't work out how to deserialise a Json object to String in a TypeAdapter.</p>

<pre><code>public class JsonStringTypeAdapter extends TypeAdapter&lt;String&gt; {

    @Override
    public void write(JsonWriter writer, String t) throws IOException {
        writer.jsonValue(t);
    }

    @Override
    public String read(JsonReader reader) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
</code></pre>

<p>I know Jackson has an annotation for this. Any ideas for doing it with GSON?</p>