Package 

Object Json


  • 
    public class Json
    
                        

    Utility object for converting Kotlin objects to JSON representations.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final static Json INSTANCE
    • Method Summary

      Modifier and Type Method Description
      final Object toJSONPrimitive(Object value) Converts any Kotlin object to a JSON-compatible primitive or complex type.
      final Object toJsonPrimitive(Object $self) Extension function for Any?
      final <T extends Any> JSONObject toJSONObject(T data) Converts any Kotlin object to a JSONObject.
      final <T extends Collection<Any>> JSONArray toJSONArray(T data) Converts a Collection to a JSONArray.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toJSONPrimitive

         final Object toJSONPrimitive(Object value)

        Converts any Kotlin object to a JSON-compatible primitive or complex type.

        Handles various primitive types, collections, maps, and custom objects. Special handling is provided for Rust-derived sealed classes.

        Parameters:
        value - The value to convert to a JSON-compatible form
      • toJSONObject

         final <T extends Any> JSONObject toJSONObject(T data)

        Converts any Kotlin object to a JSONObject.

        Uses reflection to get all properties of the object and converts each to a JSON-compatible form.

        Parameters:
        data - The object to convert
      • toJSONArray

         final <T extends Collection<Any>> JSONArray toJSONArray(T data)

        Converts a Collection to a JSONArray.

        Each element in the collection is converted to a JSON-compatible form.

        Parameters:
        data - The collection to convert