public class OAJson extends Object
This is also able to work with POJO classes that dont always have pkey properties, but instead use importMatch properties or linkMany
unique. OAJson will find (or create) the correct OAObject that does have the matching value(s).
ex: Customer.id, and Customer.custNumber, where OAObject Customer has an Id (pkey) and custNumber (int prop, but not key). The Pojo class
does not have to have the Id.
also, a link could be an importMatch (ex: custNumber can be flagged as an importMatch).
Internally uses (/depends on) Jackson's ObjectMapper.
Note: this is not thread safe.
| Modifier and Type | Class and Description |
|---|---|
static class |
OAJson.StackItem |
| Modifier and Type | Field and Description |
|---|---|
protected static Object |
lock |
protected com.fasterxml.jackson.databind.ObjectMapper |
objectMapper |
| Constructor and Description |
|---|
OAJson() |
| Modifier and Type | Method and Description |
|---|---|
protected static String |
_convertMethodArgumentsToJson(OAJson oaj,
Method method,
Object[] argValues,
List<String>[] lstIncludePropertyPathss,
int[] skipParams) |
void |
addPropertyPath(String propertyPath)
Add property paths to include when writing.
|
void |
addPropertyPaths(List<String> pps) |
void |
afterReadCallback(com.fasterxml.jackson.databind.JsonNode node,
Object objNew) |
protected void |
afterReadJson() |
void |
beforeReadCallback(com.fasterxml.jackson.databind.JsonNode node) |
void |
clearPropertyPaths() |
static OAObjectKey |
convertJsonSinglePartIdToObjectKey(Class<? extends OAObject> clazz,
String strSinglePartId) |
static Object[] |
convertJsonToMethodArguments(com.fasterxml.jackson.databind.node.ArrayNode nodeArray,
Method method,
int[] skipParams) |
protected static Object[] |
convertJsonToMethodArguments(OAJson oaj,
com.fasterxml.jackson.databind.node.ArrayNode nodeArray,
Method method,
int[] skipParams) |
static Object[] |
convertJsonToMethodArguments(String jsonArray,
Method method)
Convert a json array to the argument values of a method.
|
static String |
convertMethodArgumentsToJson(Method method,
Object[] argValues,
List<String>[] lstIncludePropertyPathss,
int[] skipParams)
Used to serialize the arguments into a Json array.
|
static OAObjectKey |
convertNumberToObjectKey(Class<? extends OAObject> clazz,
int id) |
static String |
convertObjectKeyToJsonSinglePartId(OAObjectKey oaObjKey) |
String |
convertToPretty(String json) |
static com.fasterxml.jackson.databind.ObjectMapper |
createJsonObjectMapper() |
String |
format(String json) |
OACascade |
getCascade() |
String |
getCurrentPropertyPath()
PropertyPath that is currently being read/written.
|
Map<Integer,OAObject> |
getGuidMap() |
List<OAObjectImportMatchDelegate.ImportMatch> |
getImportMatchList() |
boolean |
getIncludeAll() |
boolean |
getIncludeOwned() |
static com.fasterxml.jackson.databind.ObjectMapper |
getJsonObjectMapper() |
com.fasterxml.jackson.databind.JsonNode |
getNode(com.fasterxml.jackson.databind.JsonNode parentNode,
String propertyPath) |
com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper() |
String |
getPropertyNameCallback(Object obj,
String defaultName) |
ArrayList<String> |
getPropertyPaths() |
Object |
getPropertyValueCallback(Object obj,
String propertyName,
Object defaultValue) |
boolean |
getReadingPojo() |
Class<? extends OAObject> |
getReadObjectClass()
Used internally to know the class of the root node.
|
OAObject |
getRoot()
Root object used from call to readIntoObject.
|
OAJson.StackItem |
getStackItem() |
com.fasterxml.jackson.databind.ObjectMapper |
getUnsharedObjectMapper() |
boolean |
getUsePropertyCallback(Object obj,
String propertyName) |
boolean |
getWriteAsPojo() |
boolean |
isReadingPojo() |
<T extends OAObject> |
readIntoHub(File file,
Hub<T> hub,
boolean bIsLoading) |
<T extends OAObject> |
readIntoHub(com.fasterxml.jackson.databind.ObjectMapper om,
com.fasterxml.jackson.databind.JsonNode nodeRoot,
Hub<T> hub,
boolean bIsLoading) |
<T extends OAObject> |
readIntoHub(String json,
Hub<T> hub,
boolean bIsLoading) |
void |
readIntoObject(InputStream is,
OAObject root) |
void |
readIntoObject(InputStream is,
OAObject root,
boolean bIsLoading) |
void |
readIntoObject(String json,
OAObject root)
Read JSON into an existing root Object.
|
void |
readIntoObject(String json,
OAObject root,
boolean bIsLoading) |
<T> List<T> |
readList(File file,
Class<T> clazz,
boolean bIsLoading) |
<T> List<T> |
readList(InputStream stream,
Class<T> clazz,
boolean bIsLoading) |
<T> List<T> |
readList(String json,
Class<T> clazz,
boolean bIsLoading) |
<K,V> Map<K,V> |
readMap(String json,
Class<K> clazzKey,
Class<V> clazzValue,
boolean bIsLoading) |
<T> T |
readObject(File file,
Class<T> clazz,
boolean bIsLoading)
Convert a JSON file to an OAObject graph.
|
<T> T |
readObject(InputStream stream,
Class<T> clazz,
boolean bIsLoading)
Read JSON from stream into Object.
|
<T> T |
readObject(String json,
Class<T> clazz)
Read Object from JSON.
|
<T> T |
readObject(String json,
Class<T> clazz,
boolean bIsLoading)
Convert a JSON string to an Object graph.
|
com.fasterxml.jackson.databind.JsonNode |
readTree(InputStream is) |
com.fasterxml.jackson.databind.JsonNode |
readTree(String json) |
protected void |
reset() |
void |
setCaseInsensitive() |
void |
setIncludeAll(boolean b)
Flag to know if ALL references are included, default is false.
Note that references will be used, so that duplicates are not created and circular references are avoided. |
void |
setIncludeOwned(boolean b)
Flag to know if owned references are included, default is true.
|
void |
setReadingPojo(boolean b)
Flag to know if the JSON that is being read is from a POJO.
|
void |
setStackItem(OAJson.StackItem si) |
void |
setWriteAsPojo(boolean b)
This will include additional properties that could be used in Pojo, but are not needed in the OAObject.
For example, pojos that do not have pkey properties and rely other data for uniqueness. |
String |
toJson(Object obj) |
String |
write(Hub<? extends OAObject> hub) |
void |
write(Hub<? extends OAObject> hub,
File file) |
String |
write(Object obj)
Convert OAObject to a JSON string, including any owned Links, and links in propertyPaths.
|
void |
write(Object obj,
File file)
Convert OAObject to a JSON string, including any owned Links, and links in propertyPaths.
|
void |
write(Object obj,
OutputStream stream)
Convert OAObject to a JSON stream.
|
protected static final Object lock
protected com.fasterxml.jackson.databind.ObjectMapper objectMapper
public List<OAObjectImportMatchDelegate.ImportMatch> getImportMatchList()
public void setReadingPojo(boolean b)
public boolean isReadingPojo()
public boolean getReadingPojo()
public void setIncludeOwned(boolean b)
public boolean getIncludeOwned()
public void setIncludeAll(boolean b)
public boolean getIncludeAll()
protected void reset()
public Class<? extends OAObject> getReadObjectClass()
public void addPropertyPath(String propertyPath)
public void clearPropertyPaths()
public static com.fasterxml.jackson.databind.ObjectMapper getJsonObjectMapper()
public static com.fasterxml.jackson.databind.ObjectMapper createJsonObjectMapper()
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
public com.fasterxml.jackson.databind.ObjectMapper getUnsharedObjectMapper()
public void setCaseInsensitive()
public String toJson(Object obj) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic String write(Object obj) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic String convertToPretty(String json) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic String format(String json) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic void write(Object obj, File file) throws com.fasterxml.jackson.core.JsonProcessingException, IOException
com.fasterxml.jackson.core.JsonProcessingExceptionIOExceptionpublic void write(Object obj, OutputStream stream) throws com.fasterxml.jackson.core.JsonProcessingException, IOException
com.fasterxml.jackson.core.JsonProcessingExceptionIOExceptionpublic <T> T readObject(String json, Class<T> clazz) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic OAJson.StackItem getStackItem()
public void setStackItem(OAJson.StackItem si)
public OAObject getRoot()
public void readIntoObject(String json, OAObject root) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic void readIntoObject(String json, OAObject root, boolean bIsLoading) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic void readIntoObject(InputStream is, OAObject root) throws com.fasterxml.jackson.core.JsonProcessingException, IOException
com.fasterxml.jackson.core.JsonProcessingExceptionIOExceptionpublic void readIntoObject(InputStream is, OAObject root, boolean bIsLoading) throws com.fasterxml.jackson.core.JsonProcessingException, IOException
com.fasterxml.jackson.core.JsonProcessingExceptionIOExceptionpublic <T> T readObject(String json, Class<T> clazz, boolean bIsLoading) throws com.fasterxml.jackson.core.JsonProcessingException
bIsLoading - (default = false), if true then threadLocal.setLoading(true) will be used before loading.com.fasterxml.jackson.core.JsonProcessingExceptionprotected void afterReadJson()
public <T> T readObject(InputStream stream, Class<T> clazz, boolean bIsLoading) throws com.fasterxml.jackson.core.JsonProcessingException, IOException
com.fasterxml.jackson.core.JsonProcessingExceptionIOExceptionpublic <T> T readObject(File file, Class<T> clazz, boolean bIsLoading) throws com.fasterxml.jackson.core.JsonProcessingException, IOException
com.fasterxml.jackson.core.JsonProcessingExceptionIOExceptionpublic <K,V> Map<K,V> readMap(String json, Class<K> clazzKey, Class<V> clazzValue, boolean bIsLoading) throws com.fasterxml.jackson.core.JsonProcessingException, IOException
com.fasterxml.jackson.core.JsonProcessingExceptionIOExceptionpublic <T> List<T> readList(String json, Class<T> clazz, boolean bIsLoading) throws com.fasterxml.jackson.core.JsonProcessingException, IOException
com.fasterxml.jackson.core.JsonProcessingExceptionIOExceptionpublic <T> List<T> readList(File file, Class<T> clazz, boolean bIsLoading) throws com.fasterxml.jackson.core.JsonProcessingException, IOException
com.fasterxml.jackson.core.JsonProcessingExceptionIOExceptionpublic <T> List<T> readList(InputStream stream, Class<T> clazz, boolean bIsLoading) throws com.fasterxml.jackson.core.JsonProcessingException, IOException
com.fasterxml.jackson.core.JsonProcessingExceptionIOExceptionpublic OACascade getCascade()
public void write(Hub<? extends OAObject> hub, File file) throws com.fasterxml.jackson.core.JsonProcessingException, IOException
com.fasterxml.jackson.core.JsonProcessingExceptionIOExceptionpublic String write(Hub<? extends OAObject> hub) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic <T extends OAObject> void readIntoHub(File file, Hub<T> hub, boolean bIsLoading) throws Exception
Exceptionpublic <T extends OAObject> void readIntoHub(String json, Hub<T> hub, boolean bIsLoading) throws Exception
Exceptionpublic <T extends OAObject> void readIntoHub(com.fasterxml.jackson.databind.ObjectMapper om, com.fasterxml.jackson.databind.JsonNode nodeRoot, Hub<T> hub, boolean bIsLoading) throws Exception
Exceptionpublic static OAObjectKey convertJsonSinglePartIdToObjectKey(Class<? extends OAObject> clazz, String strSinglePartId)
public static OAObjectKey convertNumberToObjectKey(Class<? extends OAObject> clazz, int id)
public static String convertObjectKeyToJsonSinglePartId(OAObjectKey oaObjKey)
public static String convertMethodArgumentsToJson(Method method, Object[] argValues, List<String>[] lstIncludePropertyPathss, int[] skipParams) throws Exception
Exceptionprotected static String _convertMethodArgumentsToJson(OAJson oaj, Method method, Object[] argValues, List<String>[] lstIncludePropertyPathss, int[] skipParams) throws Exception
Exceptionpublic static Object[] convertJsonToMethodArguments(String jsonArray, Method method) throws Exception
Exceptionpublic static Object[] convertJsonToMethodArguments(com.fasterxml.jackson.databind.node.ArrayNode nodeArray, Method method, int[] skipParams) throws Exception
Exceptionprotected static Object[] convertJsonToMethodArguments(OAJson oaj, com.fasterxml.jackson.databind.node.ArrayNode nodeArray, Method method, int[] skipParams) throws Exception
Exceptionpublic com.fasterxml.jackson.databind.JsonNode readTree(String json) throws Exception
Exceptionpublic com.fasterxml.jackson.databind.JsonNode readTree(InputStream is) throws Exception
Exceptionpublic com.fasterxml.jackson.databind.JsonNode getNode(com.fasterxml.jackson.databind.JsonNode parentNode,
String propertyPath)
public String getCurrentPropertyPath()
public Object getPropertyValueCallback(Object obj, String propertyName, Object defaultValue)
public void beforeReadCallback(com.fasterxml.jackson.databind.JsonNode node)
public void afterReadCallback(com.fasterxml.jackson.databind.JsonNode node,
Object objNew)
public void setWriteAsPojo(boolean b)
public boolean getWriteAsPojo()
Copyright © 1999–2025 ViaOA. All rights reserved.