googleapis / googleapis/google-cloud-java

[java-firestore] Firestore - surprising behavior of object mapping annotations

Open
#13,146 5 comments 1 reaction 0 assignees View on GitHub
api: firestore semver: major type: feature request
Dominant language
Java
Stars
2.1k
Forks
1.2k
Avg merge
1d 23h
Merged PRs (30d)
154

Description

If `com.google.cloud.firestore.annotation.Exclude` annotation used on a property, but not on a getter, it is ignored. The same is true for `@PropertyName`

For @PropertyName it gets even more surprising if the property is public and there is a public getter. In that case a field is duplicated, one instance under the property's name and the other one under the getter's name.

Example that replicates the issue:
```java
class User {
@PropertyName("user_name")
public String name;

@Exclude
private Integer age;

public User(String name, Integer age) {
this.name = name;
this.age = age;
}

public User() {
}

public String getName() {
return name;
}

public Integer getAge() {
return age;
}
}
```

This would produce the following fields:
```
{age=integer_value: 29
, name=string_value: "abc"
, user_name=string_value: "abc"
}
```

But I would expect this:
```
{
user_name=string_value: "abc"
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.