Skip to content

GenericTypeResolver broken in 6.2.0 (possible regression of #24963) #33968

Closed as not planned
@rPraml

Description

@rPraml

Hello, I want to report a possible regression in 6.2.0

We have some rest controllers that use jackson with @JsonTypeInfo annotations.

With 6.1.x the attached code works and returns the expected JSON: [ { "type" : "one" }, { "type" : "two" } ]
With 6.2.0, the type properties are missing and [ {}, {} ] is returned.

I've tracked down, that this commit may have changed the behaviour: e788aeb (#24963)

I'm unsure, if this is "works as designed" or if that code path got lost through this commit:
The method declaration public <T extends BaseType> List<T> get() may be a bit strange, but valid java syntax.
When I use this method declaration public List<BaseType> get(), the controller will work again. (@quaff, @jhoeller FYI)

@RestController
public class TestController {
	@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
	@JsonSubTypes({
			@JsonSubTypes.Type(value = SubType1.class, name = "one"),
			@JsonSubTypes.Type(value = SubType2.class, name = "two")
	})
	public static class BaseType {

	}

	public static class SubType1 extends BaseType {
	}

	public static class SubType2 extends BaseType {
	}

	@GetMapping(value = "/test", produces = MediaType.APPLICATION_JSON_VALUE)
	public <T extends BaseType> List<T> get() {
		List<T> list = new ArrayList<>();
		list.add((T) new SubType1());
		list.add((T) new SubType2());
		return list;
	}
}

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: supersededAn issue that has been superseded by another

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions