nastra commented on a change in pull request #4266:
URL: https://github.com/apache/iceberg/pull/4266#discussion_r820435584
##########
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.
Review comment:
It does 2 things.
1. It generates a JSON Helper class with `@JsonProperty` annotations that
looks liks this (note that this is directly copied from the generated class):
```
/**
* Utility type used to correctly read immutable object from JSON
representation.
* @deprecated Do not use this type directly, it exists only for the
<em>Jackson</em>-binding infrastructure
*/
@Generated(from = "CreateNamespaceRequest", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json extends CreateNamespaceRequest {
@Nullable Namespace namespace;
@Nullable Map<String, String> properties = Collections.emptyMap();
@JsonProperty("namespace")
public void setNamespace(Namespace namespace) {
this.namespace = namespace;
}
@JsonProperty("properties")
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
@Override
public Namespace namespace() { throw new
UnsupportedOperationException(); }
@Override
public Map<String, String> properties() { throw new
UnsupportedOperationException(); }
}
```
2. It generates a utility method with the `@JsonCreator` annotation, that
looks exactly like this:
```
/**
* @param json A JSON-bindable data structure
* @return An immutable value type
* @deprecated Do not use this method directly, it exists only for the
<em>Jackson</em>-binding infrastructure
*/
@Deprecated
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
static ImmutableCreateNamespaceRequest fromJson(Json json) {
ImmutableCreateNamespaceRequest.Builder builder =
ImmutableCreateNamespaceRequest.builder();
if (json.namespace != null) {
builder.namespace(json.namespace);
}
if (json.properties != null) {
builder.putAllProperties(json.properties);
}
return builder.build();
}
```
Note that this only happens when we add `@JsonSerialize` /
`@JsonDeserialize` to the class
--
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]