Skip to content

Commit 379b022

Browse files
committed
Support overriding default proxy check
1 parent 4dd2241 commit 379b022

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/com/esotericsoftware/kryo/Kryo.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ public Registration getRegistration (Class type) {
558558

559559
Registration registration = classResolver.getRegistration(type);
560560
if (registration == null) {
561-
if (Proxy.isProxyClass(type)) {
561+
if (isProxy(type)) {
562562
// If a Proxy class, treat it like an InvocationHandler because the concrete class for a proxy is generated.
563563
registration = getRegistration(InvocationHandler.class);
564564
} else if (!type.isEnum() && Enum.class.isAssignableFrom(type) && type != Enum.class) {
@@ -1263,6 +1263,16 @@ public boolean isClosure (Class type) {
12631263
return type.getName().indexOf('/') >= 0;
12641264
}
12651265

1266+
/** Returns true if the specified type is a proxy. When true, Kryo uses {@link InvocationHandler} instead of the specified type
1267+
* to find the class {@link Registration}.
1268+
* <p>
1269+
* This can be overridden to support alternative proxy checks. The default implementation delegates to
1270+
* {@link Proxy#isProxyClass(Class)}. */
1271+
public boolean isProxy (Class type) {
1272+
if (type == null) throw new IllegalArgumentException("type cannot be null.");
1273+
return Proxy.isProxyClass(type);
1274+
}
1275+
12661276
/** Tracks the generic type arguments and actual classes for type variables in the object graph during seralization.
12671277
* <p>
12681278
* When serializing a type with a single type parameter, {@link Generics#nextGenericClass() nextGenericClass} will return the

0 commit comments

Comments
 (0)