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

Navigating a class that extends Map results in the map's value type masking real properties [DATAREDIS-490] #1066

Closed
spring-projects-issues opened this issue Apr 8, 2016 · 2 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Apr 8, 2016

Greg Turnquist opened DATAREDIS-490 and commented

Navigating a type like this:

class Pipeline extends HashMap<String, Object> implements Timestamped {
  @JsonIgnore
  Long lastModified

  @JsonIgnore
  String getApplication() {
    return super.get("application")
  }

  @JsonIgnore
  String getName() {
    return super.get("name")
  }

  void setName(String name) {
    super.put("name", name)
  }

  @Override
  @JsonIgnore
  String getId() {
    return super.get("id")
  }

  void setId(String id) {
    super.put("id", id)
  }
}

...when used as a subtype of another enclosing type, causes Spring Data Redis to look that the Map's value type...

	public TypeInformation<?> getActualType() {

		if (isMap()) {
			return getMapValueType();
		}

		if (isCollectionLike()) {
			return getComponentType();
		}

		return this;
	}

Hence, the Pipeline above will resolve itself to Object. At that point, a finder method based on "application" property will look for Object.application, and come up with null, since that doesn't exist. Hence, property traversal fails.

NOTE: Is this a Spring Data Commons issue?


Affects: 1.7.1 (Hopper SR1)

Issue Links:

  • DATACMNS-847 Use AccessType.PROPERTY for entites that extend Map
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 18, 2016

Christoph Strobl commented

Yeah that one seems to need some treatment in sd-commons. Since we use AccessType.FIELD by default it only picks up the properties of the Map. Things like size and stores those. One would need to switch to AccessType.PROPERTY to have it do the expected

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 18, 2016

Oliver Drotbohm commented

Extending HashMap is begging for trouble. Even if we got Spring Data to do the right thing here there will be something downstream that will apply special Map logic to this type. Suggest to refactor to contain a Map and delegate get(…) and put(…) calls if needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants