chaokunyang commented on code in PR #2701: URL: https://github.com/apache/fory/pull/2701#discussion_r2424619751
########## integration_tests/graalvm_tests/src/main/java/org/apache/fory/graalvm/FeatureTestExample.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.fory.graalvm; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import org.apache.fory.Fory; +import org.apache.fory.config.Language; + +public class FeatureTestExample { + + // Test class with private constructor (problematic for creation) + public static class ProblematicClass { + private String value; + + private ProblematicClass() { + // Private constructor + } + + public ProblematicClass(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + // Test interface for proxy + public interface TestInterface { + String getValue(); + + void setValue(String value); + } + + // Simple invocation handler + public static class TestInvocationHandler implements InvocationHandler { + private String value; + + public TestInvocationHandler(String value) { + this.value = value; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if ("getValue".equals(method.getName())) { + return value; + } else if ("setValue".equals(method.getName())) { + value = (String) args[0]; + return null; + } + return null; + } + } + + public static void main(String[] args) { + System.out.println("Testing Fory GraalVM Feature..."); + + Fory fory = + Fory.builder().withLanguage(Language.JAVA).withRefTracking(true).withCodegen(false).build(); + + fory.register(ProblematicClass.class); + fory.register(TestInvocationHandler.class); + + // Register proxy interface + Fory.addProxyInterface(TestInterface.class); + + try { + // Test 1: Serialize/deserialize problematic class + ProblematicClass original = new ProblematicClass("test-value"); + byte[] serialized = fory.serialize(original); + ProblematicClass deserialized = (ProblematicClass) fory.deserialize(serialized); + + if (!"test-value".equals(deserialized.getValue())) { + throw new RuntimeException("Problematic class test failed"); + } + System.out.println("✓ Problematic class serialization test passed"); Review Comment: ditto, don't use Problematic, since it's supproted by fory now with this PR -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
