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

val with simple camelCase and @JsonIgnore is included #172

Closed
nilswieber opened this issue Aug 9, 2018 · 5 comments
Closed

val with simple camelCase and @JsonIgnore is included #172

nilswieber opened this issue Aug 9, 2018 · 5 comments

Comments

@nilswieber
Copy link

Given the following code, i would presume that it prints an JSON Object with "message" as the only field:

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule

fun main(args: Array<String>) {
    println(ObjectMapper().registerModule(KotlinModule()).writeValueAsString(Test()))
}

class Test{
    @JsonIgnore
    val cCase = 1
    @JsonIgnore
    val camelCase = 1

    val message = "hello world"
}

If this code is run it prints:
{"message":"hello world","ccase":1}

The field cCase shouldn't be included. I think it's related to how the byte code is generated by the Kotlin Compiler. The class Test is translated to the following Java Code:

public final class Test {
   @JsonIgnore
   private final int cCase = 1;
   @JsonIgnore
   private final int camelCase = 1;
   @NotNull
   private final String message = "hello world";

   public final int getCCase() {
      return this.cCase;
   }

   public final int getCamelCase() {
      return this.camelCase;
   }

   @NotNull
   public final String getMessage() {
      return this.message;
   }
}

Notice that the getter for cCase is named getCCase().

@nilswieber nilswieber changed the title val with simple camelCase and JsonIgnore is Included val with simple camelCase and @JsonIgnore is included Aug 9, 2018
@rkschamer
Copy link

rkschamer commented Feb 14, 2019

I have the same issue. I've created some example project here, in case you want to try it: https://github.com/flawi/jackson-ignore-issue

And I also can confirm that the issue persists for

  • Jackson: 2.9.8
  • Kotlin: 1.3.21

@TrueShirshov
Copy link

I think link to workaround posted here can be helpful for someone. Just use @get:JsonIgnore annotation.

@hartmut-co-uk
Copy link

still a workaround only / extra annotations/code though :)

@k163377
Copy link
Contributor

k163377 commented Feb 17, 2023

Issues last updated before 2020 are closed.
If the problem is reproduced in the latest version, please reopen.

@k163377 k163377 closed this as completed Feb 17, 2023
@k163377
Copy link
Contributor

k163377 commented Mar 3, 2023

This issue will be fixed in #630.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants