You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EmptyObjectGenerator is a Kotlin utility class that automatically generates objects with desired default values. It
inherently supports Kotlin's primitive types and extends its support to 1-dimensional and 2-dimensional arrays.
Additionally, users have the flexibility to add custom support.
Note : If your object has self-referencing behavior, please read and use 'Self Reference.
Default Supported types
val string:Stringval char:Charval int:Intval long:Longval float:Floatval double:Doubleval boolean:Booleanval list:List<Any>
val set:Set<Any>
val map:Map<Any, Any>
val stringSingleArray:Array<String>
val charSingleArray:CharArrayval intSingleArray:IntArrayval longSingleArray:LongArrayval floatSingleArray:FloatArrayval doubleSingleArray:DoubleArrayval booleanSingleArray:BooleanArrayval listArray:Array<List<Any>>
val setArray:Array<Set<Any>>
val mapArray:Array<Map<Any, Any>>
val stringNestedArray:Array<Array<String>>
val charNestedARray:Array<CharArray>
val intNestedArray:Array<IntArray>
val longNestedArray:Array<LongArray>
val floatNestedArray:Array<FloatArray>
val doubleNestedArray:Array<DoubleArray>
val booleanNestedArray:Array<BooleanArray>
val listNestedArray:Array<Array<List<Any>>>
val setNestedArray:Array<Array<Set<Any>>>
val mapNestedArray:Array<Array<Map<Any, Any>>>
Supported Method
Method
Description
generate
Used to create an empty object.
addCustomSupportType
Allows specifying the return type for the generated empty object.
clearCustomTypeSupport
Resets all registered custom types.
Generate Method Supported Parameter
Parameter
Type
Description
Default Value
Required
clazz
KClass
The Kotlin class for which an object needs to be generated.
-
Yes
isNullable
Boolean
Internal data can be null. This can only be used if there is a nullable mark.
false
No
defaultString
String
The default value for String types.
"empty"
No
defaultChar
Char
The default value for Char types.
Char.MIN_VALUE
No
defaultInt
Int
The default value for Int types.
0
No
defaultLong
Long
The default value for Long types.
0L
No
defaultFloat
Float
The default value for Float types.
0.0f
No
defaultDouble
Double
The default value for Double types.
0.0
No
defaultBoolean
Boolean
The default value for Boolean types.
false
No
defaultArraySize
Int
The default size for 1-dimensional arrays.
0
No
defaultInnerArraySize
Int
The default size for 2-dimensional arrays.
0
No
emptyValue
EmptyValue?
Customizable empty value for additional support beyond primitive types.
null
No
addCustomSupportType Supported Parameter
Parameter
Description
Type
Default Value
Required
clazz
Represents the class of the supported custom Kotlin type.
KClass<*>
-
Yes
defaultValue
Represents the default value for the specified Kotlin type.
Any
-
Yes
clearCustomTypeSupport
Parameter
Description
Type
Default Value
Required
(No parameters)
(No parameters for this method)
-
-
No
How use
The usual method involves receiving the return value and then utilizing it.
val result:YourClass=EmptyObjectGenerator.generate(YourClass::class)
You can use it directly within the method block without receiving the return value.