code: public static <Param> PathParamSerializer<Optional<Param>> optional(String name,
                                                                          Function<String, Param> deserialize,
                                                                          Function<Param, String> serialize) {
  
          return new NamedPathParamSerializer<Optional<Param>>("Optional(" + name + ")") {
              @Override
              public PSequence<String> serialize(Optional<Param> parameter) {
                  return parameter.map(p -> TreePVector.singleton(serialize.apply(p))).orElse(TreePVector.empty());
              }
  
              @Override
              public Optional<Param> deserialize(PSequence<String> parameters) {
                  if (parameters.isEmpty()) {
                      return Optional.empty();
                  } else {
                      return Optional.of(deserialize.apply(parameters.get(0)));
                  }
              }
          };
      }
docs: Create a PathParamSerializer for optional parameters.