Github user anew commented on a diff in the pull request:

    https://github.com/apache/twill/pull/14#discussion_r86275759
  
    --- Diff: 
twill-core/src/main/java/org/apache/twill/internal/json/ResourceReportAdapter.java
 ---
    @@ -59,4 +72,61 @@ public ResourceReport fromJson(String json) {
       public ResourceReport fromJson(Reader reader) {
         return gson.fromJson(reader, ResourceReport.class);
       }
    +
    +  /**
    +   * A type adapter for serializing {@code Collection<TwillRunResources>} 
correctly
    +   */
    +  private static final class ResourceReportTypeAdapterFactory implements 
TypeAdapterFactory {
    +
    +    @SuppressWarnings("unchecked")
    +    @Override
    +    public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    +      if (!Collection.class.isAssignableFrom(type.getRawType())) {
    +        return null;
    +      }
    +
    +      if (!(type.getType() instanceof ParameterizedType)) {
    +        return null;
    +      }
    +
    +      TypeToken<?> valueType = TypeToken.get(((ParameterizedType) 
type.getType()).getActualTypeArguments()[0]);
    +      return (TypeAdapter<T>) collectionAdapter(gson, valueType);
    +    }
    +
    +    private <V> TypeAdapter<Collection<V>> collectionAdapter(Gson gson, 
TypeToken<V> valueType) {
    +      final TypeAdapter<V> valueAdapter = gson.getAdapter(valueType);
    +      return new TypeAdapter<Collection<V>>() {
    +        @Override
    +        public void write(JsonWriter writer, @Nullable Collection<V> 
collection) throws IOException {
    +          if (collection == null) {
    +            writer.nullValue();
    +            return;
    +          }
    +          writer.beginArray();
    +          for (V value : collection) {
    +            valueAdapter.write(writer, value);
    +          }
    +          writer.endArray();
    +        }
    +
    +        @Override
    +        public Collection<V> read(JsonReader reader) throws IOException {
    +          if (reader.peek() == JsonToken.NULL) {
    +            reader.nextNull();
    +            return null;
    +          }
    +          if (reader.peek() != JsonToken.BEGIN_ARRAY) {
    +            return null;
    --- End diff --
    
    shouldn't this throw an exception? It is a violation of the codec.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to