nastra commented on a change in pull request #4266:
URL: https://github.com/apache/iceberg/pull/4266#discussion_r819571302
##########
File path:
core/src/main/java/org/apache/iceberg/rest/requests/CreateNamespaceRequest.java
##########
@@ -19,81 +19,42 @@
package org.apache.iceberg.rest.requests;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.util.Map;
-import java.util.Objects;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
-import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
-import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
-import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.immutables.value.Value;
/**
* A REST request to create a namespace, with an optional set of properties.
+ *
+ * Note that Immutable classes by definition don't have a default no-arg
constructor (which is required for Jackson),
+ * therefore the @{@link JsonSerialize}/@{@link JsonDeserialize} annotations
on the class will generate what's
+ * necessary for Jackson-binding to properly work with this class.
*/
-public class CreateNamespaceRequest {
-
- private Namespace namespace;
- private Map<String, String> properties;
[email protected]
+@JsonSerialize(as = ImmutableCreateNamespaceRequest.class)
+@JsonDeserialize(as = ImmutableCreateNamespaceRequest.class)
+public abstract class CreateNamespaceRequest {
- public CreateNamespaceRequest() {
- // Needed for Jackson Deserialization.
- }
+ public abstract Namespace namespace();
- private CreateNamespaceRequest(Namespace namespace, Map<String, String>
properties) {
- this.namespace = namespace;
- this.properties = properties;
- validate();
- }
+ public abstract Map<String, String> properties();
- CreateNamespaceRequest validate() {
- Preconditions.checkArgument(namespace != null, "Invalid namespace: null");
- return this;
+ public static CreateNamespaceRequest of(Namespace namespace) {
+ return
ImmutableCreateNamespaceRequest.builder().namespace(namespace).build();
}
- public Namespace namespace() {
- return namespace;
- }
-
- public Map<String, String> properties() {
- return properties != null ? properties : ImmutableMap.of();
+ public static CreateNamespaceRequest of(Namespace namespace, Map<String,
String> properties) {
Review comment:
the purpose of the `of()` methods is just to simplify things on the
caller's side
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]