Thanks for the reply, Tatu. Unfortunately, 2.6.7 works exactly the same like 2.6.3 does. However, if I switch to 2.9.6 (and I hope I'll migrate the project I work at too), the output is slightly different: `class com.sun.proxy.$Proxy0`. The assertion error is never thrown though.
On Wednesday, August 15, 2018 at 1:58:14 PM UTC+3, Tatu Saloranta wrote: > > On Tue, Aug 14, 2018 at 1:30 PM, Lyubomyr Shaydariv > <[email protected] <javascript:>> wrote: > > Hello, > > > > I've faced with an issue where I need to work with dynamic proxies since > I > > find them a very convenient way allowing to reduce the amount of code > > dramatically. Please consider the following code: > > > > interface IUserDto { > > > > @JsonProperty(value = "name", access = JsonProperty.Access.READ_ONLY) > > String getName(); > > > > void setName(String name); > > > > interface IUserCreateDto > > extends IUserDto { > > > > @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY, > > required = true) > > void setName(String name); > > > > } > > > > static void main(final String... args) > > throws IOException { > > final ClassLoader classLoader = IUserDto.class.getClassLoader(); > > final ObjectMapper objectMapper = new ObjectMapper(); > > objectMapper.registerModule(new SimpleModule() > > .addDeserializer(IUserCreateDto.class, new > > JsonDeserializer<IUserCreateDto>() { > > @Override > > public IUserCreateDto deserialize(final JsonParser parser, final > > DeserializationContext context) { > > return (IUserCreateDto) Proxy.newProxyInstance(classLoader, new Class[]{ > > IUserCreateDto.class }, (proxy, method, args) -> { > > throw new AssertionError("This never happens"); > > }); > > } > > }) > > ); > > final IUserCreateDto userCreateDto = > > objectMapper.readValue("{\"name\":\"John\"}", IUserCreateDto.class); > > System.out.println(userCreateDto.getClass()); > > } > > > > } > > > > > > > > For some reason, the invocation handler defined for the proxy is never > > invoked. Hence, the last System.out.println() simply prints `class > > com.sun.proxy.$Proxy2`, but I would expect the `readValue` method to > fail > > because of the intentional assertion error specified in the invocation > > handler. My question is: what am I doing wrong and if it's possible to > make > > Jackson work with dynamic proxies? > > > > Here are my Jackson dependencies: > > > > * com.fasterxml.jackson.core:jackson-core:2.6.3 > > * com.fasterxml.jackson.core:jackson-databind:2.6.3 > > As usual, I would suggest trying out: > > 1. The last path version of minor version you have: 2.6.7; if same > behavior > 2. Try one of later maintained versions: either 2.8.11 or .29.6 > > to verify issue still exists, as 2.6.3 is bit old version and there > have been more fixes. > > Proxy types are not supported by default for deserialization, but > custom deserializers should work I think. > If later versions do not work (which seem likely), I would file an > issue at github against `jackson-databind`. > > -+ Tatu +- > -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
