Comments (4)
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.
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.
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.
2.10.1 has been released containing the fix
from kotshi.
Related Issues (20)
- Investigate support for inline classes HOT 1
- all of the objects have one companion object in ram ?!!?! HOT 3
- Migrate to KSP
- Implementation documentation or sample app? HOT 5
- Kotlin 1.5 borked HOT 3
- Generated annotation not found when compiling against Java 11 HOT 10
- Alternative annotation for custom names HOT 9
- v2.9.0: Excess code generated in adapters (Kapt) HOT 4
- Possible race condition in KSP factory generation HOT 12
- 2.10.1 KSP generated adapters have trouble with generic typealiases when there is a default value HOT 3
- Serialisation issue is sallowed HOT 2
- Unresolved reference: KotshiAppJsonAdapterFactory HOT 2
- KotshiApplicationJsonAdapterFactory does not have a companion object HOT 6
- Usage with JVM 11 HOT 3
- Backend Internal error HOT 5
- [Intermittent] No JsonAdapter is getting created for random response classes after migrating to ksp from kapt HOT 4
- KSP: Failed to analyze class HOT 5
- Kotshi clashing with Micronaut DI HOT 10
- Best practices in multi-modular projects HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotshi.