Git Product home page Git Product logo

Comments (4)

ansman avatar ansman commented on September 15, 2024

So what is happening is that Kotshi internally matches the variable names to your property names. It then gets confused because the there is both a type and a variable with the same name.

Although this can be fixed, I would highly recommend that your type names to start with an upper case and your property names start with a lower case letter as this can cause all kinds of issues.
You can use the JsonProperty annotation to change the name of the serialized value:

@JsonSerializable
data class MyClazz(
    @JsonProperty(name = "Int")
    val int: Int? = null
)

from kotshi.

daviddenton avatar daviddenton commented on September 15, 2024

Agreed. We would normally definitely name the parameters normally with lowercase. The issue is that we're building this for an OSS library - http4k-connect, which uses Kotshi to generate the adapters for a bunch of services, including AWS:

The structure of the Amazon JSON looks like this - where the name of the fields starts with an Upper-case. The naming of the classes in the lib is identical to the name of the field (the objects were generated by computer):

{
   "AddReplicaRegions": [ 
      { 
         "KmsKeyId": "string",
         "Region": "string"
      }
   ],
   "ClientRequestToken": "string",
   "Description": "string",
   "ForceOverwriteReplicaSecret": boolean,
   "KmsKeyId": "string",
   "Name": "string",
   "SecretBinary": blob,
   "SecretString": "string",
   "Tags": [ 
      { 
         "Key": "string",
         "Value": "string"
      }
   ]
}

We get that this would be a change, but it is inconsistent with the Kapt generators and more people might come across the same issue in the future (causing you the maintainer more headaches 😉 ). It's your call obvs - I can submit a patch if you will accept it and feel like you're too busy 😄 .

from kotshi.

ansman avatar ansman commented on September 15, 2024

I've added a fix and will release it soon. It doesn't technically fix all cases, it can still happen if your type is lower case but there really isn't an easy way to fix this.

It's definitely up to you but personally I would generate your data classes with lower cased names (you'd have to have some logic here anyway in case the key has a space or - in it for example) and add @JsonProperty, but that's again up to you of course.

from kotshi.

ansman avatar ansman commented on September 15, 2024

2.10.1 has been released containing the fix

from kotshi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.