Skip to content

Support for SpEL pointing to related entities in projection on first level. #2325

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

Closed
venkat125 opened this issue Jul 13, 2021 · 3 comments
Closed
Assignees
Labels
type: bug A general bug

Comments

@venkat125
Copy link

venkat125 commented Jul 13, 2021

Hi Team, i was trying out simple json response by mapping the nested DTO Projection values to the root Projection (node / object) by following this SDN doc

public interface PersonProjection {
    String getName();
    
    @Value("#{target.currentLocation.city.name}")
    String getCityName();

    @Value("#{target.currentLocation.city.regionalState.name}")
    String getStateName();
}

expected output:

{ "name": "Dhoni", "cityName": "qwerqwer", "stateName": "zxvcxzcvc" }
But, it throws the following error stating currentLocation is null as below: (but it has value)

WARN 13600 --- [nio-8080-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: EL1007E: Property or field 'city' cannot be found on null; nested exception is com.fasterxml.jackson.databind.JsonMappingException: EL1007E: Property or field 'city' cannot be found on null (through reference chain: com.sun.proxy.$Proxy162["currentLocation"])]

For reference and brevity, i'm posting the stackoverflow link.

where the 1st and 2nd case is working. But, not the 3rd case.
Is there anyway we can achieve this? Or correct me if i'm wrong.
Thanks Team.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 13, 2021
@meistermeier meistermeier self-assigned this Jul 14, 2021
meistermeier added a commit that referenced this issue Jul 14, 2021
@meistermeier
Copy link
Collaborator

Thanks for reporting this. The usage of only in the entity defined relationships' properties in SpEL was indeed a missing constellation we did not cover.
The other ones are working because the resolution already switched to look at the entities but it did not for the first level.
There is now a 6.1.3-GH-2325-SNAPSHOT available. Would be really helpful if you could check if your project returns the right results with this.

To get the version, please add following to your pom

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j</artifactId>
    <version>6.1.3-SNAPSHOT</version>
</dependency>
<repositories>
  <repository>
    <id>spring-milestones</id>
    <name>Spring Milestones</name>
    <url>https://repo.spring.io/milestone</url>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
  </repository>
  <repository>
    <id>spring-snapshots</id>
    <name>Spring Snapshots</name>
    <url>https://repo.spring.io/snapshot</url>
    <releases>
      <enabled>false</enabled>
    </releases>
  </repository>
</repositories>

@meistermeier meistermeier added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 14, 2021
@meistermeier meistermeier added this to the 6.1.3 (2021.0.3) milestone Jul 14, 2021
@meistermeier meistermeier changed the title Couldn't map the nested projection values to root object using SpEL. But, working in 1st level object. Support for SpEL pointing to related entities in projection on first level. Jul 14, 2021
@meistermeier
Copy link
Collaborator

Fixed with f23071b

@venkat125
Copy link
Author

That works. Thanks @meistermeier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants