Experiment with spring-boot version: in 1.3.7.RELEASE (spring data 2.4.4) decoratedClass is absent, but in 1.4.0.RELEASE (spring data 2.5.2) it is present
I'd like get clean JSON, when using Projection as DTO with RestController. However, in the best case we get JSON, most of which contain links to dekoratedClass. {"name":"Dmitry","id":1,"decoratedClass":"ru.inkontext.domain.Person", "adress":{"id":1,"decoratedClass":"ru.inkontext.domain.Adress","city":"Surgut"}}
Decide by Oliver Gierke
Looks like this is caused by proxies created through Spring's ProxyFactory now also implementing a new DecoratingProxy, which exposes getDecoratedClass() and our TargetAware interface that's in place to mask the artificial proxy properties doesn't mask that newly introduced attribute. I can adapt our TargetAware accordingly.
A temporary workaround would be to redeclare the getDecoratedClass() method on your projection interface and annotate it with @JsonIgnore.
Looks like this is caused by proxies created through Spring's ProxyFactory now also implementing a new DecoratingProxy, which exposes getDecoratedClass() and our TargetAware interface that's in place to mask the artificial proxy properties doesn't mask that newly introduced attribute. I can adapt our TargetAware accordingly.
A temporary workaround would be to redeclare the getDecoratedClass() method on your projection interface and annotate it with @JsonIgnore
This decide with @JsonIgnoregetDecoratedClass() is worked.
But it don't work for query methods of Repository, which return Projection: Unable to locate Attribute with the the given name decoratedClass on this ManagedType ru.inkontext.domain.Person
I do not use this method in my project and @Ignore tests in example tests.
Thank you
Dmitry Stolbov opened DATACMNS-909 and commented
Experiment with spring-boot version: in 1.3.7.RELEASE (spring data 2.4.4) decoratedClass is absent, but in 1.4.0.RELEASE (spring data 2.5.2) it is present
I'd like get clean JSON, when using Projection as DTO with RestController. However, in the best case we get JSON, most of which contain links to dekoratedClass.
{"name":"Dmitry","id":1,"decoratedClass":"ru.inkontext.domain.Person", "adress":{"id":1,"decoratedClass":"ru.inkontext.domain.Adress","city":"Surgut"
}}Decide by Oliver Gierke
Looks like this is caused by proxies created through Spring's ProxyFactory now also implementing a new DecoratingProxy, which exposes getDecoratedClass() and our TargetAware interface that's in place to mask the artificial proxy properties doesn't mask that newly introduced attribute. I can adapt our TargetAware accordingly.
A temporary workaround would be to redeclare the getDecoratedClass() method on your projection interface and annotate it with
@JsonIgnore
.Tests below imaging matter of question.
RestController
Without Projection
mockMvc.perform(get("/rest/persons/1"))
.andExpect(jsonPath("id").value(1)
.andExpect(jsonPath("decoratedClass").doesNotExist());
Projection created by Repository
mockMvc.perform(get("/rest/persons/1/projected"))
.andExpect(jsonPath("id").value(1))
.andExpect(jsonPath("decoratedClass").value("java.util.HashMap"));
Projection created by Repository with Generic
mockMvc.perform(get("/rest/persons/1/projectedClass"))
.andExpect(jsonPath("id").value(1))
.andExpect(jsonPath("decoratedClass").value("java.util.HashMap"));
Projection created by Projection Factory
mockMvc.perform(get("/rest/persons/1/adressCity"))
.andExpect(jsonPath("id").value(1))
.andExpect(jsonPath("decoratedClass").value("ru.inkontext.domain.Person"));
Standard Sring Data REST API
without Projection
mockMvc.perform(get("/rest/api/persons/1"))
.andExpect(jsonPath("id").doesNotExist())
.andExpect(jsonPath("_links").exists());
with Projection
mockMvc.perform(get("/rest/api/persons/1?projection=adressCity"))
.andExpect(status().isOk())
.andExpect(jsonPath("id").value(1))
.andExpect(jsonPath("_links").exists());
Affects: 1.11.4 (Gosling SR4), 1.12.2 (Hopper SR2), 1.13 M1 (Ingalls)
Reference URL: https://github.com/stolbovd/decoratedClass.git
Backported to: 1.12.3 (Hopper SR3), 1.11.5 (Gosling SR5)
The text was updated successfully, but these errors were encountered: