stevenschlansker commented on code in PR #2250:
URL: https://github.com/apache/fury/pull/2250#discussion_r2101387948


##########
java/fury-format/src/test/java/org/apache/fury/format/encoder/ImplementInterfaceTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fury.format.encoder;
+
+import lombok.Data;
+import org.apache.fury.annotation.FuryField;
+import org.apache.fury.format.row.binary.BinaryRow;
+import org.apache.fury.memory.MemoryBuffer;
+import org.apache.fury.memory.MemoryUtils;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class ImplementInterfaceTest {
+
+  public interface InterfaceType {
+    int getF1();
+
+    String getF2();
+
+    NestedType getNested();
+
+    PoisonPill getPoison();
+  }
+
+  public interface NestedType {
+    @FuryField(nullable = false)
+    String getF3();
+  }
+
+  public static class PoisonPill {}
+
+  @Data
+  static class ImplementInterface implements InterfaceType {
+    public int f1;
+    public String f2;
+    public NestedType nested;
+    public PoisonPill poison = new PoisonPill();
+
+    public ImplementInterface(final int f1, final String f2) {
+      this.f1 = f1;
+      this.f2 = f2;
+    }
+  }
+
+  @Data
+  static class ImplementNestedType implements NestedType {
+    public String f3;
+
+    public ImplementNestedType(final String f3) {
+      this.f3 = f3;
+    }
+  }
+
+  static {
+    Encoders.registerCustomCodec(PoisonPill.class, new PoisonPillCodec());
+    Encoders.registerLazyBeanInterface(InterfaceType.class);
+    Encoders.registerLazyBeanInterface(NestedType.class);
+  }
+
+  @Test
+  public void testInterfaceTypes() {
+    final InterfaceType bean1 = new ImplementInterface(42, "42");
+    final RowEncoder<InterfaceType> encoder = 
Encoders.bean(InterfaceType.class);
+    final BinaryRow row = encoder.toRow(bean1);
+    final MemoryBuffer buffer = MemoryUtils.wrap(row.toBytes());
+    row.pointTo(buffer, 0, buffer.size());
+    final InterfaceType deserializedBean = encoder.fromRow(row);

Review Comment:
   Well, I actually did not get this to work today. Either the type checks are 
too loose and include random things like `interface List<E>` or they are too 
strong and do not include the interface type I am interested in. Having a list 
of known safe types to implement made this easy. I can take another look 
tomorrow.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@fury.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@fury.apache.org
For additional commands, e-mail: commits-h...@fury.apache.org

Reply via email to