@@ -0,0 +1,3062 @@
+/*%0A * Copyright (C) 2017 Square, Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.squareup.moshi.recipes;%0A%0Aimport com.squareup.moshi.JsonAdapter;%0Aimport com.squareup.moshi.JsonQualifier;%0Aimport com.squareup.moshi.JsonReader;%0Aimport com.squareup.moshi.JsonWriter;%0Aimport com.squareup.moshi.Moshi;%0Aimport com.squareup.moshi.Types;%0Aimport com.squareup.moshi.recipes.Unwrap.EnvelopeJsonAdapter.Enveloped;%0Aimport com.squareup.moshi.recipes.models.Card;%0Aimport java.io.IOException;%0Aimport java.lang.annotation.Annotation;%0Aimport java.lang.annotation.Retention;%0Aimport java.lang.reflect.Type;%0Aimport java.util.Set;%0A%0Aimport static java.lang.annotation.RetentionPolicy.RUNTIME;%0A%0Afinal class Unwrap %7B%0A  public static void main(String%5B%5D args) throws Exception %7B%0A    String json = %22%22%0A        + %22%7B%5C%22data%5C%22:%22%0A        + %22  %7B%5Cn%22%0A        + %22    %5C%22rank%5C%22: %5C%224%5C%22,%5Cn%22%0A        + %22    %5C%22suit%5C%22: %5C%22CLUBS%5C%22%5Cn%22%0A        + %22  %7D%22%0A        + %22%7D%22;%0A    Moshi moshi = new Moshi.Builder().add(EnvelopeJsonAdapter.FACTORY).build();%0A    JsonAdapter%3CCard%3E adapter = moshi.adapter(Card.class, Enveloped.class);%0A    Card out = adapter.fromJson(json);%0A    System.out.println(out);%0A  %7D%0A%0A  public static final class EnvelopeJsonAdapter extends JsonAdapter%3CObject%3E %7B%0A    public static final JsonAdapter.Factory FACTORY = new Factory() %7B%0A      @Override%0A      public JsonAdapter%3C?%3E create(Type type, Set%3C? extends Annotation%3E annotations, Moshi moshi) %7B%0A        Set%3C? extends Annotation%3E delegateAnnotations =%0A            Types.nextAnnotations(annotations, Enveloped.class);%0A        if (delegateAnnotations == null) %7B%0A          return null;%0A        %7D%0A        Type envelope =%0A            Types.newParameterizedTypeWithOwner(EnvelopeJsonAdapter.class, Envelope.class, type);%0A        JsonAdapter%3CEnvelope%3C?%3E%3E delegate = moshi.nextAdapter(this, envelope, delegateAnnotations);%0A        return new EnvelopeJsonAdapter(delegate);%0A      %7D%0A    %7D;%0A%0A    @Retention(RUNTIME) @JsonQualifier public @interface Enveloped %7B%0A    %7D%0A%0A    private static final class Envelope%3CT%3E %7B%0A      final T data;%0A%0A      Envelope(T data) %7B%0A        this.data = data;%0A      %7D%0A    %7D%0A%0A    private final JsonAdapter%3CEnvelope%3C?%3E%3E delegate;%0A%0A    EnvelopeJsonAdapter(JsonAdapter%3CEnvelope%3C?%3E%3E delegate) %7B%0A      this.delegate = delegate;%0A    %7D%0A%0A    @Override public Object fromJson(JsonReader reader) throws IOException %7B%0A      return delegate.fromJson(reader).data;%0A    %7D%0A%0A    @Override public void toJson(JsonWriter writer, Object value) throws IOException %7B%0A      delegate.toJson(new Envelope%3C%3E(value));%0A    %7D%0A  %7D%0A%7D%0A

Add Unwrap JsonAdapter.Factory sample