Class JsonText
java.lang.Object
org.diabetestechnology.drh.service.http.util.JsonText
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Custom serializer for byte arrays.static interface
static class
Custom serializer for JSON text. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetJsonObject
(String jsonString) Parses a JSON string and returns aJsonText.JsonObjectResult
indicating the outcome.
-
Constructor Details
-
JsonText
public JsonText()
-
-
Method Details
-
getJsonObject
Parses a JSON string and returns aJsonText.JsonObjectResult
indicating the outcome.This method attempts to parse the provided JSON string into a
Map
. If the JSON string contains a key named$class
, it tries to instantiate an object of that class using the parsed JSON map and the original JSON string. The result of the parsing and potential instantiation is encapsulated in aJsonText.JsonObjectResult
object.Possible results include:
JsonText.JsonObjectResult.ValidResult
- The JSON was parsed successfully and an instance of the specified class was created.JsonText.JsonObjectResult.ValidResultClassNotFound
- The JSON was parsed successfully, but the specified class was not found.JsonText.JsonObjectResult.ValidResultClassNotInstantiated
- The JSON was parsed successfully, but the specified class could not be instantiated.JsonText.JsonObjectResult.ValidUntypedResult
- The JSON was parsed successfully but does not specify a class.JsonText.JsonObjectResult.InvalidResult
- The JSON could not be parsed or other errors occurred.
Usage example:
String jsonString = "{\"$class\":\"com.example.MyClass\", \"key\":\"value\"}"; JsonObjectResult result = myObject.getJsonObject(jsonString); if (result instanceof JsonObjectResult.ValidResult) { // handle valid result } else if (result instanceof JsonObjectResult.InvalidResult) { // handle invalid result }
- Parameters:
jsonString
- the JSON string to parse- Returns:
- a
JsonText.JsonObjectResult
object representing the outcome of the parsing and potential instantiation
-