-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
3.0Issue planned for initial 3.0 releaseIssue planned for initial 3.0 releasepr-welcomeIssue for which progress most likely if someone submits a Pull RequestIssue for which progress most likely if someone submits a Pull Request
Description
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
Annotations such as @JsonIgnore are not honoured in Jackson 3 when the type being serialised is a JDK proxy whose class name starts with jdk.. I believe this will be the case when all of the proxy's interfaces are public.
Version Information
3.0.2
Reproduction
Run the following with Jackson Databind 2.20.1 and 3.0.2 on the classpath:
package com.example;
import java.lang.reflect.Proxy;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
public class JacksonJdkProxyProblem {
public static void main(String[] args) throws JsonProcessingException {
Object proxied = Proxy.newProxyInstance(JacksonJdkProxyProblem.class.getClassLoader(), new Class[] {Example.class}, (proxy, method, methodArgs) -> {
return method.getName();
});
System.out.println(tools.jackson.databind.json.JsonMapper.builder().build().writeValueAsString(proxied));
System.out.println(new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(proxied));
}
public static interface Example {
String getValue();
@JsonIgnore(true)
String getIgnoredValue();
}
}It will produce the following output:
{"ignoredValue":"getIgnoredValue","value":"getValue"}
{"value":"getValue"}
Expected behavior
I expected the following output:
{"value":"getValue"}
{"value":"getValue"}
Additional context
I think dc10783 is the cause. It has added jdk. to the prefixes that are used to identify JDK classes.
Perhaps classes whose name starts with jdk.proxy could be special-cased?
Metadata
Metadata
Assignees
Labels
3.0Issue planned for initial 3.0 releaseIssue planned for initial 3.0 releasepr-welcomeIssue for which progress most likely if someone submits a Pull RequestIssue for which progress most likely if someone submits a Pull Request