Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.springframework.core.TypeDescriptor.getAnnotations() should return the method annotation when it wraps the return parameter of the Method [SPR-6979] #11644

Closed
spring-projects-issues opened this issue Mar 13, 2010 · 6 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Thomas Scheiblauer opened SPR-6979 and commented

If a TypeDescriptor is created from the return parameter of a method e.g.
TypeDescriptor typeDescr = new TypeDescriptor(new MethodParameter(method, -1))
where -1 denotes the return parameter then
typeDescr.getAnnotations() should return the annotations applied to the method.
3.0.1 crashes with an array index out of bounds exception because the called MethodParameter.getParameterAnnotations() tries to index an empty Annotations Array with -1,
the current 3.0.2 nightly fixes at least the exception by returning an empty Array in this case.
Since e.g. org.springframework.core.convert.ConversionService or org.codehaus.jackson.map.JsonSerializer<Object> need the TypeDescriptor for type conversions either MethodParameter.getParameterAnnotations() or TypeDescriptor.getAnnotations() should return the method annotations in case of a wrapped return parameter.
I bumped into this problem while trying to modify the getTypeDescriptorForSerializer method in this mvc ajax example:
https://src.springframework.org/svn/spring-samples/mvc-ajax/trunk/src/main/java/org/springframework/samples/mvc/ajax/json/FormatAnnotationIntrospector.java
according to the TODO note.


Affects: 3.0.1, 3.0.2

Attachments:

Referenced from: commits 65b0a8f

@spring-projects-issues
Copy link
Collaborator Author

Thomas Scheiblauer commented

the topic should read: 'org.springframework.core.convert.TypeDescriptor.getAnnotations() ...'
I patched TypeDescriptor.java to work as described above and modified the mentioned example code as proposed in it's TODO comment and it worked as expected. I will attach the patches for examination.

@spring-projects-issues
Copy link
Collaborator Author

Thomas Scheiblauer commented

patch for org/springframework/core/convert/TypeDescriptor.java

@spring-projects-issues
Copy link
Collaborator Author

Thomas Scheiblauer commented

This is my improved Version of FormatAnnotationIntrospector.java from the aforementioned example which handles setters and getters (as proposed in the TODO comments) instead of trying to find a possibly not existing private field that is named after the "property part" of the setter/getter methods

@spring-projects-issues
Copy link
Collaborator Author

Thomas Scheiblauer commented

Annotations for the serializer/deserializer converters get now annotated like this (tested and working after applying the typedescriptor.patch and using the improved FormatAnnotationIntrospector.java):
public class Test {
private Date date;

public Test() {
	date = new Date();
}

@DateTimeFormat(pattern = "yyyy-mm-dd hh:mm:ss")
public Date getDate() {
	return date;
}
public void setDate(@DateTimeFormat(pattern = "yyyy-mm-dd hh:mm:ss") Date date) {
	this.date = date;
}

}

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Addressed for 3.0.2, as part of a general overhaul of TypeDescriptor and PropertyTypeDescriptor. This will be available in tonight's 3.0.2 snapshot - feel free to give it an early try if you have the chance, and let me know whether it works for you.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Thomas Scheiblauer commented

I have just tested the current 3.0.2 snapshot (CI-632) and it works as expected :)

thx,
Tom

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants