Skip to content

Annotations on an interface that's part of a JDK proxy are not honored with Jackson 3 #5416

@wilkinsona

Description

@wilkinsona

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

No one assigned

    Labels

    3.0Issue planned for initial 3.0 releasepr-welcomeIssue for which progress most likely if someone submits a Pull Request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions