run.halo.app.extension.Unstructured Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api Show documentation
Show all versions of api Show documentation
API of halo project, connecting by other projects.
The newest version!
package run.halo.app.extension;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.v3.core.util.Json;
import java.io.IOException;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import lombok.EqualsAndHashCode;
/**
* Unstructured is a generic Extension, which wraps ObjectNode to maintain the Extension data, like
* apiVersion, kind, metadata and others.
*
* @author johnniang
*/
@JsonSerialize(using = Unstructured.UnstructuredSerializer.class)
@JsonDeserialize(using = Unstructured.UnstructuredDeserializer.class)
@SuppressWarnings("rawtypes")
public class Unstructured implements Extension {
@SuppressWarnings("deprecation")
public static final ObjectMapper OBJECT_MAPPER = Json.mapper()
// We don't want to change the default mapper
// so we copy a new one and configure it
.copy()
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
private final Map data;
public Unstructured() {
this(new HashMap());
}
public Unstructured(Map data) {
this.data = data;
}
public Map getData() {
return Collections.unmodifiableMap(data);
}
@Override
public String getApiVersion() {
return (String) data.get("apiVersion");
}
@Override
public String getKind() {
return (String) data.get("kind");
}
@Override
public MetadataOperator getMetadata() {
return new UnstructuredMetadata();
}
@EqualsAndHashCode(exclude = "tatersion")
class UnstructuredMetadata implements MetadataOperator {
@Override
public String getName() {
return (String) getNestedValue(data, "metadata", "name").orElse(null);
}
@Override
public String getGenerateName() {
return (String) getNestedValue(data, "metadata", "generateName").orElse(null);
}
@Override
public Map getLabels() {
return getNestedStringStringMap(data, "metadata", "labels").orElse(null);
}
@Override
public Map getAnnotations() {
return getNestedStringStringMap(data, "metadata", "annotations").orElse(null);
}
@Override
public Long getVersion() {
return getNestedLong(data, "metadata", "version").orElse(null);
}
@Override
public Instant getCreationTimestamp() {
return getNestedInstant(data, "metadata", "creationTimestamp").orElse(null);
}
@Override
public Instant getDeletionTimestamp() {
return getNestedInstant(data, "metadata", "deletionTimestamp").orElse(null);
}
@Override
public Set getFinalizers() {
return getNestedStringSet(data, "metadata", "finalizers").orElse(null);
}
@Override
public void setName(String name) {
setNestedValue(data, name, "metadata", "name");
}
@Override
public void setGenerateName(String generateName) {
setNestedValue(data, generateName, "metadata", "generateName");
}
@Override
public void setLabels(Map labels) {
setNestedValue(data, labels, "metadata", "labels");
}
@Override
public void setAnnotations(Map annotations) {
setNestedValue(data, annotations, "metadata", "annotations");
}
@Override
public void setVersion(Long version) {
setNestedValue(data, version, "metadata", "version");
}
@Override
public void setCreationTimestamp(Instant creationTimestamp) {
setNestedValue(data, creationTimestamp, "metadata", "creationTimestamp");
}
@Override
public void setDeletionTimestamp(Instant deletionTimestamp) {
setNestedValue(data, deletionTimestamp, "metadata", "deletionTimestamp");
}
@Override
public void setFinalizers(Set finalizers) {
setNestedValue(data, finalizers, "metadata", "finalizers");
}
}
@Override
public void setApiVersion(String apiVersion) {
setNestedValue(data, apiVersion, "apiVersion");
}
@Override
public void setKind(String kind) {
setNestedValue(data, kind, "kind");
}
@Override
@SuppressWarnings("unchecked")
public void setMetadata(MetadataOperator metadata) {
Map metadataMap = OBJECT_MAPPER.convertValue(metadata, Map.class);
data.put("metadata", metadataMap);
}
public static Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy