### Question:
JavaProxyEnricherFactory { public Object asSerializable(final ClassLoader loader, final String plugin, final String key, final Object instanceToWrap) { final Class<?>[] interfaces = instanceToWrap.getClass().getInterfaces(); final boolean isSerializable = Stream.of(interfaces).anyMatch(i -> i == Serializable.class || i == Externalizable.class); if (isSerializable && !instanceToWrap.getClass().getName().startsWith("org.apache.johnzon.core.")) { return instanceToWrap; } final Class[] api = isSerializable ? interfaces : Stream.concat(Stream.of(Serializable.class), Stream.of(interfaces)).toArray(Class[]::new); return Proxy .newProxyInstance(selectLoader(api, loader), api, new DelegatingSerializableHandler(instanceToWrap, plugin, key)); }  Object asSerializable(final ClassLoader loader, final String plugin, final String key,
            final Object instanceToWrap);  }### Answer:
@Test void serialization() throws IOException, ClassNotFoundException { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final JavaProxyEnricherFactory factory = new JavaProxyEnricherFactory(); final Translator proxyBased = Translator.class .cast(factory .asSerializable(loader, getClass().getSimpleName(), Translator.class.getName(), new InternationalizationServiceFactory(Locale::getDefault) .create(Translator.class, loader))); assertEquals("ok", proxyBased.message()); DynamicContainerFinder.SERVICES.put(Translator.class, proxyBased); DynamicContainerFinder.LOADERS.put(getClass().getSimpleName(), Thread.currentThread().getContextClassLoader()); try { final Translator fromApi = Serializer.roundTrip(proxyBased); assertEquals(fromApi, proxyBased); assertSame(Proxy.getInvocationHandler(fromApi), Proxy.getInvocationHandler(proxyBased)); } finally { DynamicContainerFinder.LOADERS.clear(); DynamicContainerFinder.SERVICES.remove(Translator.class); } }
@Test void defaultMethod() { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final JavaProxyEnricherFactory factory = new JavaProxyEnricherFactory(); final SomeDefault proxyBased = SomeDefault.class .cast(factory .asSerializable(loader, getClass().getSimpleName(), SomeDefault.class.getName(), new SomeDefault() { @Override public String get() { return "ok"; } })); assertEquals("ok", proxyBased.get()); }