chaokunyang commented on code in PR #2701: URL: https://github.com/apache/fory/pull/2701#discussion_r2453789384
########## integration_tests/graalvm_tests/src/main/java/org/apache/fory/graalvm/FeatureTestExample.java: ########## @@ -0,0 +1,124 @@ +/* + * 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; +import org.apache.fory.util.GraalvmSupport; + +public class FeatureTestExample { + + public static class PrivateConstructorClass { + private String value; + + private PrivateConstructorClass() { + // Private constructor + } + + public PrivateConstructorClass(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(PrivateConstructorClass.class); + fory.register(TestInvocationHandler.class); + + // Register proxy interface + GraalvmSupport.registerProxySupport(TestInterface.class); + + try { + // Test 1: Serialize/deserialize class with private constructor + PrivateConstructorClass original = new PrivateConstructorClass("test-value"); + byte[] serialized = fory.serialize(original); + PrivateConstructorClass deserialized = (PrivateConstructorClass) fory.deserialize(serialized); Review Comment: Please also assert `fory.getClassResolver().getSerializer(PrivateConstructorClass.class) instanceof Generated` -- 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]
