Package blue.endless.jankson
Class JsonObject
java.lang.Object
blue.endless.jankson.JsonElement
blue.endless.jankson.JsonObject
- All Implemented Interfaces:
Cloneable,Map<String,JsonElement>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()clone()booleancontainsKey(Object key) booleancontainsValue(Object val) entrySet()Creates a semi-live shallow copy instead of a live viewboolean<E> EbooleangetBoolean(String key, boolean defaultValue) bytechargetComment(String name) Returns the comment "attached to" a given key-value mapping, which is to say, the comment appearing immediately before it or the single-line comment to the right of it.getDelta(JsonObject defaults) Gets a minimal set of key-value-comment settings which, if added to the supplied JsonObject, would produce this JsonObject.doublefloatintlongIf there is an entry at this key, and that entry is a json object, return it.shortinthashCode()booleanisEmpty()keySet()Returns a defensive copy instead of a live viewput(String key, JsonElement elem) Replaces a key-value mapping in this object if it exists, or adds the mapping to the end of the object if it doesn't.put(String key, JsonElement elem, String comment) Replaces a key-value mapping in this object if it exists, or adds the mapping to the end of the object if it doesn't.voidputAll(Map<? extends String, ? extends JsonElement> map) putDefault(String key, JsonElement elem, String comment) <T> TputDefault(String key, T elem, Class<? extends T> clazz, String comment) May return null if the existing object can't be marshalled to the target class<T> TputDefault(String key, T elem, String comment) May return null if the existing object can't be marshalled to elem's class<E> ErecursiveGet(Class<E> clazz, String key) Gets a (potentially nested) element from this object if it exists.<E extends JsonElement>
ErecursiveGetOrCreate(Class<E> clazz, String key, E fallback, String comment) Gets a (potentially nested) element from this object if it exists, or creates it and any intermediate objects needed to put it at the indicated location in the hierarchy.voidsetComment(String name, String comment) voidsetMarshaller(Marshaller marshaller) intsize()toJson(boolean comments, boolean newlines, int depth) voidtoJson(Writer w, JsonGrammar grammar, int depth) toString()values()Methods inherited from class blue.endless.jankson.JsonElement
toJson, toJson, toJson, toJsonMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
marshaller
-
-
Constructor Details
-
JsonObject
public JsonObject()
-
-
Method Details
-
getObject
If there is an entry at this key, and that entry is a json object, return it. Otherwise returns null. -
put
Replaces a key-value mapping in this object if it exists, or adds the mapping to the end of the object if it doesn't. Returns the old value mapped to this key if there was one. -
putDefault
@Nonnull public JsonElement putDefault(@Nonnull String key, @Nonnull JsonElement elem, @Nullable String comment) -
putDefault
May return null if the existing object can't be marshalled to elem's class -
putDefault
@Nullable public <T> T putDefault(@Nonnull String key, @Nonnull T elem, Class<? extends T> clazz, @Nullable String comment) May return null if the existing object can't be marshalled to the target class -
getDelta
Gets a minimal set of key-value-comment settings which, if added to the supplied JsonObject, would produce this JsonObject. See BasicTests::testDiffAgainstDefaults() for more details on this comparison.- If a key is present in the default and not in the object, it's skipped
- If a key is an object, a deep (recursive) comparison occurs. Comments are ignored in this comparison.
- All other types, including lists, receive a shallow comparison of its value. The comment is ignored in this comparison.
- Whether deep or shallow, if the key is found to be identical in value to its default, it is skipped.
- If the key is found to be different than its default, the key, value, and comment are represented in the output.
-
getComment
Returns the comment "attached to" a given key-value mapping, which is to say, the comment appearing immediately before it or the single-line comment to the right of it. -
setComment
-
toJson
- Specified by:
toJsonin classJsonElement
-
toJson
- Specified by:
toJsonin classJsonElement- Throws:
IOException
-
toString
-
equals
-
hashCode
public int hashCode() -
setMarshaller
-
getMarshaller
-
get
-
getBoolean
-
getByte
-
getChar
-
getShort
-
getInt
-
getLong
-
getFloat
-
getDouble
-
recursiveGet
Gets a (potentially nested) element from this object if it exists.- Parameters:
clazz- The expected class of the elementkey- The keys of the nested elements, separated by periods, such as "foo.bar.baz"- Returns:
- The element at that location, if it exists and is of the proper type, otherwise null.
-
recursiveGetOrCreate
public <E extends JsonElement> E recursiveGetOrCreate(@Nonnull Class<E> clazz, @Nonnull String key, @Nonnull E fallback, @Nullable String comment) Gets a (potentially nested) element from this object if it exists, or creates it and any intermediate objects needed to put it at the indicated location in the hierarchy.- Parameters:
clazz- The expected class of the elementkey- The keys of the nested elements, separated by periods, such as "foo.bar.baz"- Returns:
- The element at that location if it exists, or the newly-created element if it did not previously exist.
-
clone
- Specified by:
clonein classJsonElement
-
put
Replaces a key-value mapping in this object if it exists, or adds the mapping to the end of the object if it doesn't. Returns the old value mapped to this key if there was one.- Specified by:
putin interfaceMap<String,JsonElement>
-
clear
public void clear()- Specified by:
clearin interfaceMap<String,JsonElement>
-
containsKey
- Specified by:
containsKeyin interfaceMap<String,JsonElement>
-
containsValue
- Specified by:
containsValuein interfaceMap<String,JsonElement>
-
entrySet
Creates a semi-live shallow copy instead of a live view- Specified by:
entrySetin interfaceMap<String,JsonElement>
-
get
- Specified by:
getin interfaceMap<String,JsonElement>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceMap<String,JsonElement>
-
keySet
Returns a defensive copy instead of a live view- Specified by:
keySetin interfaceMap<String,JsonElement>
-
putAll
- Specified by:
putAllin interfaceMap<String,JsonElement>
-
remove
- Specified by:
removein interfaceMap<String,JsonElement>
-
size
public int size()- Specified by:
sizein interfaceMap<String,JsonElement>
-
values
- Specified by:
valuesin interfaceMap<String,JsonElement>
-