io.getstream.core.models.CollectionData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stream-java Show documentation
Show all versions of stream-java Show documentation
Stream Feeds Java Client for backend and android integrations
package io.getstream.core.models;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;
import static io.getstream.core.utils.Serialization.convert;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.Objects;
public final class CollectionData {
private final String id;
private final String collection;
private final Map data;
@JsonCreator
public CollectionData(
@JsonProperty("collection") String collection,
@JsonProperty("id") String id,
@JsonProperty("data") Map data) {
this.collection = collection;
this.data = firstNonNull(data, Maps.newHashMap());
this.id = checkNotNull(id, "ID required");
}
public CollectionData() {
this(null, "", null);
}
public CollectionData(String id) {
this(null, id, null);
}
public static CollectionData buildFrom(T data) {
return convert(data, CollectionData.class);
}
public String getID() {
return id;
}
@JsonIgnore
public String getCollection() {
return collection;
}
@JsonAnyGetter
public Map getData() {
return data;
}
@JsonAnySetter
public CollectionData set(String key, T value) {
checkNotNull(key, "Key can't be null");
data.put(key, value);
return this;
}
public CollectionData from(T data) {
checkNotNull(data, "Can't extract data from null");
Map map = convert(data, new TypeReference
© 2015 - 2025 Weber Informatics LLC | Privacy Policy