Package org.apache.iceberg.util
Class JsonUtil
- java.lang.Object
-
- org.apache.iceberg.util.JsonUtil
-
public class JsonUtil extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
JsonUtil.FromJson<T>
static interface
JsonUtil.ToJson
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.fasterxml.jackson.core.JsonFactory
factory()
static java.lang.String
generate(JsonUtil.ToJson toJson, boolean pretty)
Helper for writing JSON with a JsonGenerator.static com.fasterxml.jackson.databind.JsonNode
get(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static boolean
getBool(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static int
getInt(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.util.List<java.lang.Integer>
getIntegerList(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.util.Set<java.lang.Integer>
getIntegerSet(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.util.Set<java.lang.Integer>
getIntegerSetOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.lang.Integer
getIntOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static long
getLong(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.util.List<java.lang.Long>
getLongList(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.lang.Long
getLongOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.util.Set<java.lang.Long>
getLongSet(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.util.Set<java.lang.Long>
getLongSetOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.lang.String
getString(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.lang.String[]
getStringArray(com.fasterxml.jackson.databind.JsonNode node)
static java.util.List<java.lang.String>
getStringList(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.util.List<java.lang.String>
getStringListOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.util.Map<java.lang.String,java.lang.String>
getStringMap(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.lang.String
getStringOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static java.util.Set<java.lang.String>
getStringSet(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
static com.fasterxml.jackson.databind.ObjectMapper
mapper()
static <T> T
parse(java.lang.String json, JsonUtil.FromJson<T> parser)
Helper for parsing JSON from a String.static void
writeIntegerArray(java.lang.String property, java.lang.Iterable<java.lang.Integer> items, com.fasterxml.jackson.core.JsonGenerator gen)
static void
writeIntegerFieldIf(boolean condition, java.lang.String key, java.lang.Integer value, com.fasterxml.jackson.core.JsonGenerator generator)
static void
writeLongArray(java.lang.String property, java.lang.Iterable<java.lang.Long> items, com.fasterxml.jackson.core.JsonGenerator gen)
static void
writeLongFieldIf(boolean condition, java.lang.String key, java.lang.Long value, com.fasterxml.jackson.core.JsonGenerator generator)
static void
writeStringArray(java.lang.String property, java.lang.Iterable<java.lang.String> items, com.fasterxml.jackson.core.JsonGenerator gen)
static void
writeStringMap(java.lang.String property, java.util.Map<java.lang.String,java.lang.String> map, com.fasterxml.jackson.core.JsonGenerator gen)
-
-
-
Method Detail
-
factory
public static com.fasterxml.jackson.core.JsonFactory factory()
-
mapper
public static com.fasterxml.jackson.databind.ObjectMapper mapper()
-
generate
public static java.lang.String generate(JsonUtil.ToJson toJson, boolean pretty)
Helper for writing JSON with a JsonGenerator.- Parameters:
toJson
- a function to produce JSON using a JsonGeneratorpretty
- whether to pretty-print JSON for readability- Returns:
- a JSON string produced from the generator
-
parse
public static <T> T parse(java.lang.String json, JsonUtil.FromJson<T> parser)
Helper for parsing JSON from a String.- Type Parameters:
T
- type of objects created by the parser- Parameters:
json
- a JSON stringparser
- a function that converts a JsonNode to a Java object- Returns:
- the parsed Java object
-
get
public static com.fasterxml.jackson.databind.JsonNode get(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getInt
public static int getInt(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getIntOrNull
public static java.lang.Integer getIntOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getLongOrNull
public static java.lang.Long getLongOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getLong
public static long getLong(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getBool
public static boolean getBool(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getString
public static java.lang.String getString(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getStringOrNull
public static java.lang.String getStringOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getStringMap
public static java.util.Map<java.lang.String,java.lang.String> getStringMap(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getStringArray
public static java.lang.String[] getStringArray(com.fasterxml.jackson.databind.JsonNode node)
-
getStringList
public static java.util.List<java.lang.String> getStringList(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getStringSet
public static java.util.Set<java.lang.String> getStringSet(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getStringListOrNull
public static java.util.List<java.lang.String> getStringListOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getIntegerList
public static java.util.List<java.lang.Integer> getIntegerList(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getIntegerSetOrNull
public static java.util.Set<java.lang.Integer> getIntegerSetOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getIntegerSet
public static java.util.Set<java.lang.Integer> getIntegerSet(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getLongList
public static java.util.List<java.lang.Long> getLongList(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getLongSetOrNull
public static java.util.Set<java.lang.Long> getLongSetOrNull(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
getLongSet
public static java.util.Set<java.lang.Long> getLongSet(java.lang.String property, com.fasterxml.jackson.databind.JsonNode node)
-
writeIntegerFieldIf
public static void writeIntegerFieldIf(boolean condition, java.lang.String key, java.lang.Integer value, com.fasterxml.jackson.core.JsonGenerator generator) throws java.io.IOException
- Throws:
java.io.IOException
-
writeLongFieldIf
public static void writeLongFieldIf(boolean condition, java.lang.String key, java.lang.Long value, com.fasterxml.jackson.core.JsonGenerator generator) throws java.io.IOException
- Throws:
java.io.IOException
-
writeIntegerArray
public static void writeIntegerArray(java.lang.String property, java.lang.Iterable<java.lang.Integer> items, com.fasterxml.jackson.core.JsonGenerator gen) throws java.io.IOException
- Throws:
java.io.IOException
-
writeLongArray
public static void writeLongArray(java.lang.String property, java.lang.Iterable<java.lang.Long> items, com.fasterxml.jackson.core.JsonGenerator gen) throws java.io.IOException
- Throws:
java.io.IOException
-
writeStringArray
public static void writeStringArray(java.lang.String property, java.lang.Iterable<java.lang.String> items, com.fasterxml.jackson.core.JsonGenerator gen) throws java.io.IOException
- Throws:
java.io.IOException
-
writeStringMap
public static void writeStringMap(java.lang.String property, java.util.Map<java.lang.String,java.lang.String> map, com.fasterxml.jackson.core.JsonGenerator gen) throws java.io.IOException
- Throws:
java.io.IOException
-
-