com.grafana.foundation.dashboard.StringOrMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grafana-foundation-sdk Show documentation
Show all versions of grafana-foundation-sdk Show documentation
A set of tools, types and libraries for building and manipulating Grafana objects.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package com.grafana.foundation.dashboard;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.Map;
@JsonDeserialize(using = StringOrMapDeserializer.class)
@JsonSerialize(using = StringOrMapSerializer.class)
public class StringOrMap {
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonUnwrapped
protected String string;
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonUnwrapped
protected Map map;
protected StringOrMap() {}
public static StringOrMap createString(String string) {
StringOrMap stringOrMap = new StringOrMap();
stringOrMap.string = string;
return stringOrMap;
}
public static StringOrMap createMap(Map map) {
StringOrMap stringOrMap = new StringOrMap();
stringOrMap.map = map;
return stringOrMap;
}
public String toJSON() throws JsonProcessingException {
if (string != null) {
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
return ow.writeValueAsString(string);
}
if (map != null) {
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
return ow.writeValueAsString(map);
}
return null;
}
}