Skip to content

Commit

Permalink
Merge pull request #210 from stevenschlansker/scs-bb-proxy-181
Browse files Browse the repository at this point in the history
Blackbird serialize Proxy objects
  • Loading branch information
cowtowncoder committed Jun 21, 2023
2 parents ec10e03 + cf044e2 commit 15969db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ private static MethodHandle init() {
}

public static Lookup privateLookupIn(Class<?> lookup, Lookup orig) {
return Unchecked.supplier(() -> (Lookup) FACTORY.invokeExact(lookup, orig)).get();
try {
return (Lookup) FACTORY.invokeExact(lookup, orig);
} catch (ReflectiveOperationException e) {
return orig;
} catch (Throwable t) {
throw Sneaky.throwAnyway(t);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.fasterxml.jackson.module.blackbird;

import java.lang.reflect.Proxy;

import com.fasterxml.jackson.databind.ObjectMapper;

public class TestAccessFallback extends BlackbirdTestBase
Expand Down Expand Up @@ -69,4 +71,19 @@ public void testDeserializeAccess() throws Exception
MyBean bean2 = abMapper.readValue(BEAN_JSON, MyBean.class);
assertEquals("a", bean2.getE());
}

public void testProxyAccessIssue181() throws Exception {
ObjectMapper om = newObjectMapper();
String val = om.writeValueAsString(Proxy.newProxyInstance(TestAccessFallback.class.getClassLoader(), new Class<?>[] { Beany.class }, (p, m, a) -> {
if (m.getName().equals("getA")) {
return 42;
}
return null;
}));
assertEquals("{\"a\":42}", val);
}

public interface Beany {
int getA();
}
}

0 comments on commit 15969db

Please sign in to comment.