Hi, how do I ignore some fields of model class whe...
# ktor
a
Hi, how do I ignore some fields of model class when serializing to json with gson?
w
I think what you're looking for is transient
a
You have lots of options actually
Annotations, custom converters
w
@Transient
That's what Java wants you to use I think (@Transient is transient keyword in Java)
a
I tried with
Expose
and
Copy code
install(ContentNegotiation) {
        gson {
            setDateFormat(DateFormat.LONG)
            excludeFieldsWithoutExposeAnnotation()
        }
    }
It didn't work
a
yup that's what I did
or am I missing something in the gson block above?
a
@Transient works for me
just tried it
Expose also works as expected
data class Test(@Expose val id: String, val excluded: Int = 5)
a
@avolkmann are you sending content with
call.respond(Test("asd"))
?
I also used Expose, but didn't work in mine
Copy code
data class User(
        val id: Long,
        val realId: Long,
        @Expose val firstName: String,
        @Expose val lastName: String,
        @Expose val profilePictureLink: String,
        @Expose val status: Int,
        @Expose val suspended: Boolean,
        @Expose val username: String
)
I have something like this
a
And what result do you get?
yes I use
call.respond(Test)
also what version do you use?
a
My bad... Intellij was running the old compiled files for some reason. I had to rm
out
and
build
directory and ran it again and now it's working. Sorry for all the confusion and fuss. Thanks for trying to help.