Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KotlinX support #160

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 2.6.0
- Kotlin Serialisation.

## 2.5.1
- Minor improvements with dependencies update.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ sealed class FrameworkVW(
properties: List<AdditionalPropertiesVM> = emptyList()
) : FrameworkVW(JAKATRA, properties)

class KotlinX(
properties: List<AdditionalPropertiesVM> = emptyList()
) : FrameworkVW(KOTLIN_X, properties)

class JakatraJavaRecords(
properties: List<AdditionalPropertiesVM> = emptyList()
) : FrameworkVW(JAKATRA_JAVA_RECORDS, properties), JavaRecords
Expand All @@ -131,6 +135,7 @@ sealed class FrameworkVW(
const val FAST_JSON = "FastJson"
const val FAST_JSON_JAVA_RECORDS = "FastJson (records)"
const val JAKATRA = "Jakarta JSON Binding"
const val KOTLIN_X = "KotlinX"
const val JAKATRA_JAVA_RECORDS = "Jakarta JSON Binding (records)"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.robohorse.robopojogenerator.postrocessing.common

import com.robohorse.robopojogenerator.models.FrameworkVW.KotlinX
import com.robohorse.robopojogenerator.models.FrameworkVW.AutoValue
import com.robohorse.robopojogenerator.models.FrameworkVW.FastJson
import com.robohorse.robopojogenerator.models.FrameworkVW.FastJsonJavaRecords
Expand Down Expand Up @@ -114,6 +115,7 @@ internal abstract class JavaPostProcessor(
}

is None,
is KotlinX,
is NoneJavaRecords -> { // NO OP
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ internal class KotlinDataClassPostProcessor(
)
}

is KotlinX -> {
generateHelper.setAnnotations(
classItem,
KotlinAnnotations.KOTLIN_X.classAnnotation,
KotlinAnnotations.KOTLIN_X.annotation,
ImportsTemplate.KOTLIN_X.imports
)
}

is LoganSquare -> {
generateHelper.setAnnotations(
classItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ internal sealed class KotlinAnnotations(
annotation = "@field:SerializedName(\"%1\$s\")"
)

object KOTLIN_X : KotlinAnnotations(
classAnnotation = "@Serializable",
annotation = "@SerialName(\"%1\$s\")"
)

object LOGAN_SQUARE : KotlinAnnotations(
classAnnotation = "@JsonObject",
annotation = "@field:JsonField(name = [\"%1\$s\"])"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ internal sealed class ImportsTemplate(
) {
object GSON : ImportsTemplate(arrayOf(SERIALIZED_NAME))

object KOTLIN_X : ImportsTemplate(arrayOf(KOTLIN_X_SERIALIZABLE, KOTLIN_X_SERIAL_NAME))

object LOGAN_SQUARE : ImportsTemplate(arrayOf(JSON_OBJECT, JSON_FIELD))

object JACKSON : ImportsTemplate(arrayOf(JSON_PROPERTY))
Expand Down Expand Up @@ -49,3 +51,6 @@ internal const val GSON_IMPORT = "import com.google.gson.Gson;"

internal const val PARCELABLE_ANDROID = "import android.os.Parcelable"
internal const val PARCELIZE_KOTLINX = "import kotlinx.parcelize.Parcelize"

internal const val KOTLIN_X_SERIALIZABLE = "import kotlinx.serialization.Serializable"
internal const val KOTLIN_X_SERIAL_NAME = "import kotlinx.serialization.SerialName"
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.robohorse.robopojogenerator.models.AdditionalPropertiesVM.UseMoshiAda
import com.robohorse.robopojogenerator.models.AdditionalPropertiesVM.UseSetters
import com.robohorse.robopojogenerator.models.AdditionalPropertiesVM.UseToString
import com.robohorse.robopojogenerator.models.ControlsModel
import com.robohorse.robopojogenerator.models.FrameworkVW
import com.robohorse.robopojogenerator.models.FrameworkVW.Jakatra
import com.robohorse.robopojogenerator.models.FrameworkVW.JakatraJavaRecords
import com.robohorse.robopojogenerator.models.FrameworkVW.AutoValue
Expand All @@ -21,6 +20,7 @@ import com.robohorse.robopojogenerator.models.FrameworkVW.Gson
import com.robohorse.robopojogenerator.models.FrameworkVW.GsonJavaRecords
import com.robohorse.robopojogenerator.models.FrameworkVW.Jackson
import com.robohorse.robopojogenerator.models.FrameworkVW.JacksonJavaRecords
import com.robohorse.robopojogenerator.models.FrameworkVW.KotlinX
import com.robohorse.robopojogenerator.models.FrameworkVW.LoganSquare
import com.robohorse.robopojogenerator.models.FrameworkVW.LoganSquareJavaRecords
import com.robohorse.robopojogenerator.models.FrameworkVW.Moshi
Expand Down Expand Up @@ -165,6 +165,13 @@ internal class PropertiesFactory {
UseKotlinParcelable()
)
),
KotlinX(
properties = listOf(
UseKotlinDataClasses(selected = true),
UseKotlinSingleDataClass(selected = true),
UseKotlinNullableFields(selected = true)
)
),
Gson(
properties = listOf(
UseKotlinDataClasses(selected = true),
Expand Down
10 changes: 5 additions & 5 deletions main/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<idea-plugin>
<id>com.robohorse.robopojogenerator</id>
<name>RoboPOJOGenerator</name>
<version>2.5.1</version>
<idea-version since-build="241" until-build="242.*"/>
<change-notes>Minor improvements with dependencies update</change-notes>
<version>2.6.0</version>
<idea-version since-build="241" until-build="243.*"/>
<change-notes>Kotlin Serialisation</change-notes>
<vendor email="robohorsed@gmail.com" url="https://github.com/robohorse/RoboPOJOGenerator">ROBOHORSE</vendor>
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceImplementation="com.robohorse.robopojogenerator.persistense.ViewStateService"/>
Expand All @@ -14,8 +14,8 @@

<description>
Intellij Idea and Android Studio plugin for JSON to POJO transformation.
Generates Java, Java Records and Kotlin POJO files from JSON: GSON, FastJSON, AutoValue (GSON), Logan Square, Jackson, Lombok, Jakarta JSON Binding, empty annotations' template. Supports: primitive types, multiple inner JSONArrays.
Keywords: JsonToPojo, Json2Pojo, Kotlin, GSON, FastJSON, AutoValue, Jackson, LoganSquare, Moshi, Parcelable, Lombok, Jakarta JSON Binding, Java records.
Generates Java, Java Records and Kotlin POJO files from JSON: GSON, FastJSON, AutoValue (GSON), Logan Square, Jackson, Lombok, Jakarta JSON Binding, KotlinX, empty annotations' template. Supports: primitive types, multiple inner JSONArrays.
Keywords: JsonToPojo, Json2Pojo, Kotlin, GSON, FastJSON, AutoValue, Jackson, LoganSquare, Moshi, Parcelable, Lombok, Jakarta JSON Binding, Java records, KotlinX.
</description>

<actions>
Expand Down
Loading