@Beta
public class Jsonya
extends java.lang.Object
provides conveniences for working with maps and lists containing maps and lists, and other datatypes too, easily convertible to json.
see JsonyaTest
for examples
Modifier and Type | Class and Description |
---|---|
static class |
Jsonya.JsonPrimitiveDeepTranslator
Converts an object to one which uses standard JSON objects where possible
(strings, numbers, booleans, maps, lists), and uses toString elsewhere
|
static class |
Jsonya.Navigator<T extends java.util.Map<?,?>> |
Modifier and Type | Method and Description |
---|---|
static Jsonya.Navigator<MutableMap<java.lang.Object,java.lang.Object>> |
at(java.lang.Object... pathSegments)
convenience for
Jsonya.Navigator.at(Object, Object...) on a newInstance() |
static java.lang.Object |
convertToJsonPrimitive(java.lang.Object x)
convenience for converting an object x to something which consists only of json primitives, doing
Object.toString() on anything which is not recognised. |
static boolean |
isJsonPrimitiveCompatible(java.lang.Object x)
tells whether
convertToJsonPrimitive(Object) returns an object which is identical to
the equivalent literal json structure. |
static Jsonya.Navigator<MutableMap<java.lang.Object,java.lang.Object>> |
newInstance()
creates a
Jsonya.Navigator backed by a newly created map;
the map can be accessed by Navigator#getMap() |
static Jsonya.Navigator<MutableMap<java.lang.Object,java.lang.Object>> |
newInstanceLiteral()
as
newInstanceTranslating(Function) using an identity function
(functionally equivalent to newInstance() but explicit about it |
static Jsonya.Navigator<MutableMap<java.lang.Object,java.lang.Object>> |
newInstancePrimitive()
as
newInstanceTranslating(Function) using a function which only supports JSON primitives:
maps and collections are traversed, strings and primitives are inserted, and everything else has toString applied. |
static Jsonya.Navigator<MutableMap<java.lang.Object,java.lang.Object>> |
newInstanceTranslating(com.google.common.base.Function<java.lang.Object,java.lang.Object> translator)
as
newInstance() but using the given translator to massage objects inserted into the Jsonya structure |
static <T extends java.util.Map<?,?>> |
of(Jsonya.Navigator<T> navigator)
creates a
Jsonya.Navigator backed by the map at the focus of the given navigator |
static <T extends java.util.Map<?,?>> |
of(T map)
creates a
Jsonya.Navigator backed by the given map (focussed at the root) |
static java.lang.String |
render(java.lang.Object focus) |
public static <T extends java.util.Map<?,?>> Jsonya.Navigator<T> of(T map)
Jsonya.Navigator
backed by the given map (focussed at the root)public static <T extends java.util.Map<?,?>> Jsonya.Navigator<T> of(Jsonya.Navigator<T> navigator)
Jsonya.Navigator
backed by the map at the focus of the given navigatorpublic static Jsonya.Navigator<MutableMap<java.lang.Object,java.lang.Object>> newInstance()
Jsonya.Navigator
backed by a newly created map;
the map can be accessed by Navigator#getMap()
public static Jsonya.Navigator<MutableMap<java.lang.Object,java.lang.Object>> at(java.lang.Object... pathSegments)
Jsonya.Navigator.at(Object, Object...)
on a newInstance()
public static Jsonya.Navigator<MutableMap<java.lang.Object,java.lang.Object>> newInstanceTranslating(com.google.common.base.Function<java.lang.Object,java.lang.Object> translator)
newInstance()
but using the given translator to massage objects inserted into the Jsonya structurepublic static Jsonya.Navigator<MutableMap<java.lang.Object,java.lang.Object>> newInstanceLiteral()
newInstanceTranslating(Function)
using an identity function
(functionally equivalent to newInstance()
but explicit about itpublic static Jsonya.Navigator<MutableMap<java.lang.Object,java.lang.Object>> newInstancePrimitive()
newInstanceTranslating(Function)
using a function which only supports JSON primitives:
maps and collections are traversed, strings and primitives are inserted, and everything else has toString applied.
see Jsonya.JsonPrimitiveDeepTranslator
public static java.lang.Object convertToJsonPrimitive(java.lang.Object x)
Object.toString()
on anything which is not recognised. see Jsonya.JsonPrimitiveDeepTranslator
public static boolean isJsonPrimitiveCompatible(java.lang.Object x)
convertToJsonPrimitive(Object)
returns an object which is identical to
the equivalent literal json structure. this is typically equivalent to saying serializing to json then
deserializing will produce something where the result is equal to the input,
modulo a few edge cases such as longs becoming ints.
note that the converse (input equal to output) may not be the case,
e.g. if the input contains special subclasses of collections of maps who care about type preservation.public static java.lang.String render(java.lang.Object focus)