-
Notifications
You must be signed in to change notification settings - Fork 478
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
HAL Forms properties should consider Jackson constructors #1274
Comments
Intriguing. I crafted a test case matching your scenario, and it actually showed the attribute you said was missing. But I tracked it down to the getter method. So this gives me a good arena to work on. |
What do you mean by I forgot to say that jackson autodetection is disabled in my environment (#1147): objectMapper
.disable(AUTO_DETECT_CREATORS)
.disable(AUTO_DETECT_FIELDS)
.disable(AUTO_DETECT_GETTERS)
.disable(AUTO_DETECT_IS_GETTERS)
.disable(AUTO_DETECT_SETTERS)
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); And I am using version 1.0.4.RELEASE |
And please note that adding getter |
What I meant is that as soon as Spring HATEOAS can spot a By dropping that, I am working on a way to read the constructor method with The one thing to figure out is if there are both (a Also, if this works @odrotbohm and I can assess whether or not to backport it to |
I can see test cases encompassing: private static class CreateCommand {
String name;
@JsonCreator
CreateCommand(@JsonProperty("otherName") String name) {
this.name = name;
}
} The resulting JSON should use @Data
private static class CreateCommand {
String name;
@JsonCreator
CreateCommand(@JsonProperty("otherName") String name) {
this.name = name;
}
} Should this one find |
I would say both properties stand. |
Although, maybe jackson just ignores any setter when it finds a JsonCreator? |
When a value object has a constructor with Jackson @JsonCreator settings, use it to gather properties for HAL-FORMS.
@odrotbohm and I discussed this in a bit more detail, and realized there is a whole story connected to this that needs to be evaluated. Thus, we've moved this into 1.2. Essentially, it's possible to create an immutable type where you have no setters. Instead, everything is built upon either constructor calls or "@With" or whatever, and the existing code would PROBABLY misread the "readOnly" nature of those types. We need to expand the existing set of unit tests to cover such scenarios, and then potentially entertain a "hint" annotation that could be applied to properties, constructors, and even getters/setters. That way, Spring HATEOAS can try to guess as best as it can, but in the corner cases where it can't figure it out, grant users ability to mark up their code to help HAL-FORMS render things as desired. |
Hello,
Let's consider the following controller:
FooController#list
produces:As you can see, property
name
is missing.The text was updated successfully, but these errors were encountered: