@Override public <T> TypeAdapter<T> create(Gson gson, final TypeToken<T> type) { if (type.getRawType().getAnnotation(RestModel.class) == null) { return null; } final TypeAdapter<T> defaultAdapter = gson.getDelegateAdapter(this, type); return new TypeAdapter<T>() { @Override public void write(JsonWriter out, T value) throws IOException { defaultAdapter.write(out, value); } @Override public T read(JsonReader in) throws IOException { T stub = defaultAdapter.read(in); if (stub == null) return null; for (Field field : ReflectionUtil.collectFields(type.getRawType())) { if (field.getAnnotation(Mandatory.class) != null) { try { field.setAccessible(true); if (field.get(stub) == null) { throw new JsonMandatoryException( String.format( "Field '%s' is mandatory, but missing in response", field.getName())); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } return stub; } }; }
@Override public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { if (!type.getRawType().equals(Broadcast.class)) { return null; } final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type); return new TypeAdapter<T>() { @Override public void write(JsonWriter out, T value) throws IOException { delegate.write(out, value); } @Override public T read(JsonReader in) throws IOException { T read = delegate.read(in); if (read instanceof Broadcast) { Broadcast broadcast = (Broadcast) read; if (broadcast.getChannel() != null && broadcast.getBroadcastOn() != null) { broadcast.getChannel().setUri(broadcast.getBroadcastOn()); } } return read; } }; }
private TypeAdapter<T> a() { TypeAdapter localTypeAdapter = f; if (localTypeAdapter != null) { return localTypeAdapter; } localTypeAdapter = c.getDelegateAdapter(e, d); f = localTypeAdapter; return localTypeAdapter; }