Skip to content

Inconsistent behavior with serde rename_all #285

@neunenak

Description

@neunenak

Here's a simple reproduction of my issue:

Cargo.toml:

[package]
name = "kotlin-typeshare-repro"
version = "0.1.0"
edition = "2024"

[dependencies]
serde = "1.0.228"
serde_json = "1.0.149"
typeshare = "1.0.5"

src/lib.rs:

use serde::{Deserialize, Serialize};
use typeshare::typeshare;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[typeshare]
pub enum DocumentType {
    PodcastEpisode,
    Podcast,
    PDF,
}

#[test]
fn test() {
    let v = DocumentType::PDF;
    assert_eq!(serde_json::to_string(&v).unwrap(), "\"p_d_f\"");
}

The test passes, you can see the (weird) "p_d_f" string that gets generated here.

However, if I run typeshare --lang kotlin --output-file Generated.kt . in the project, I get:

enum class DocumentType(val string: String) {
    @SerialName("podcast_episode")
    PodcastEpisode("podcast_episode"),
    @SerialName("podcast")
    Podcast("podcast"),
    @SerialName("pdf")
    PDF("pdf"),
}

Which has the serialization "pdf" not "p_d_f", which breaks compatibility between the rust and kotlin versions of this type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions