@Override
  public <Source> void encodeField(
      EntityFieldEncoder<Value, Source> field, Context path, Source value) {
    // TODO: implement infrastructure to make encoders aware of field annotations to avoid the
    // runtime and complexity penalty of checking them here.

    final Flags flags = field.getFlags();

    if (flags.getFlag(DatastoreFlags.KeyFlag.class).findFirst().isPresent()) {
      field.encodeOptionally(
          path.push(field.getName()),
          value,
          target -> {
            object.setKey(target.getKeyValue());
          });
    } else {
      field.encodeOptionally(
          path.push(field.getName()),
          value,
          target -> {
            object.getMutableProperties().put(field.getName(), target);
          });
    }
  }
 @Override
 public Entity build() {
   return object.build();
 }