Firestore:嵌套类的字段没有setter/field。

huangapple go评论71阅读模式
英文:

Firestore: No setter/field for field for nested class

问题

I have a class, MyOptional, that contains a generic object, in this case Foo.
I can see that I am seeing the following warnings in the logs:

No setter/field for present found on class MyOptional (fields/setters are case sensitive!)
No setter/field for empty found on class MyOptional (fields/setters are case sensitive!)
//The above two are static methods, and the below ones are fields in Foo
No setter/field for f1 found on class MyOptional
No setter/field for f2 found on class MyOptional
...as well as for all other fields

The classes look like so:

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyOptional<T> {

  private static final FSOptional<?> EMPTY = new FSOptional<>(null);

  private T value;

  public static <T> FSOptional<T> empty() {
    return (FSOptional<T>) EMPTY;
  }

  public static <T> FSOptional<T> of(T t) {
    return new FSOptional<>(t);
  }

  public boolean isPresent() {
    return value != null;
  }

  public boolean isEmpty() {
    return value == null;
  }
}

and

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Foo {
  private String f1;
  private String f2;
  ...
}

I can see in the db that the data is being saved, however it does show the results/values of my two static methods (isEmpty() and isPresent() for MyOptional).
HOWEVER, I do notice that the base object of the db is Foo instead of MyOptional...

英文:

I have a class, MyOptional, that contains a generic object, in this case Foo.
I can see that I am seeing the following warnings in the logs

No setter/field for present found on class MyOptional (fields/setters are case sensitive!)
No setter/field for empty found on class MyOptional (fields/setters are case sensitive!)
//The above two are static methods, and the below ones are fields in Foo
No setter/field for f1 found on class MyOptional
No setter/field for f2 found on class MyOptional
...as well as for all other fields

The classes look like so:

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyOptional<T> {

  private static final FSOptional<?> EMPTY = new FSOptional<>(null);

  private T value;

  public static <T> FSOptional<T> empty() {
    return (FSOptional<T>) EMPTY;
  }

  public static <T> FSOptional<T> of(T t) {
    return new FSOptional<>(t);
  }

  public boolean isPresent() {
    return value != null;
  }

  public boolean isEmpty() {
    return value == null;
  }
}

and

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Foo {
  private String f1;
  private String f2;
  ...
}

I can see in the db that the data is being saved, however it does show the results/values of my two static methods (isEmpty() and isPresent() for MyOptional).
HOWEVER, I do notice that the base object of the db is Foo instead of MyOptional...

Firestore:嵌套类的字段没有setter/field。

I DO have the default constructor and the setters and getters via @NoArgsConstructor and @Data, for both objects, so I am confused why I am still seeing this warning...any idea why and how to fix it?

答案1

得分: 1

我解决了。

我通过在每个方法上添加以下注解来解决了我的方法(isPresent和isEmpty)的警告 com.google.cloud.firestore.annotation.Exclude

至于嵌套的其他字段的警告,它与所有这些都没有真正相关。
以前,我直接将我的 Foo 对象存储在数据库中,但我将其更新为 MyOptional<Foo>。我注意到,当第一次获取对象时,我看到每个字段的所有警告,但是,一旦对象更新为新类型,我就不再看到警告了。

英文:

I figured it out.

I solved the warnings for my methods (isPresent and isEmpty) by adding the following annotation to each method
com.google.cloud.firestore.annotation.Exclude.

As for the nested the other warning for the other field, it's not really related to any of this.
Before, I was storing my Foo object directly in the database, however I updated it to be a MyOptional<Foo> instead. I noticed that when fetching the object the first time I see all the warnings for each field, however, once the object is updated to the new type, I no longer see the warnings.

huangapple
  • 本文由 发表于 2023年5月17日 17:49:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270754.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定