https://kotlinlang.org logo
#announcements
Title
# announcements
s

snowe

09/28/2017, 10:52 PM
any way to give
Pair
a different name for
first
and
second
when json serializing?
🚫 2
t

tarek

09/28/2017, 10:53 PM
I think you have to use a data class
s

snowe

09/28/2017, 10:55 PM
yeah that's what I thought.
a

agomez

09/28/2017, 10:57 PM
are you using jackson?
s

snowe

09/28/2017, 10:57 PM
@agomez yes
a

agomez

09/28/2017, 10:58 PM
you can register a mixin to customize pair serialization
mixins are handy when you need to customize the serialization of classes from 3rd party libraries
s

snowe

09/28/2017, 11:02 PM
Awesome. I have no clue how I've never heard of those before. Thank you very much
@agomez ah would this 'permanently' make Pair serialize into a different 'class'?
n

nerses

09/28/2017, 11:03 PM
it will be much easier and concise just to create specialized data class then going with Mixins
s

snowe

09/28/2017, 11:04 PM
@nerses well I would really like to retain the ability to use the
to
infix
a

agomez

09/28/2017, 11:05 PM
it will apply to pair everywhere
s

snowe

09/28/2017, 11:06 PM
@agomez yeah what I was really looking for was essentially a
typealias
but with named params, or a subclass where I could just override the properties, but it's final so I can't.
n

nerses

09/28/2017, 11:06 PM
i haven’t tried but you can import your own
to
infix method
s

snowe

09/28/2017, 11:06 PM
ah, didn't realize you could overload it.
n

nerses

09/28/2017, 11:07 PM
it’s just a method in standard lib
so in theory you should be able to do that
a

agomez

09/28/2017, 11:07 PM
or create another infix function similar to
to
but with another name
d

diesieben07

09/29/2017, 4:33 AM
You can also write a custom serializer and annotate the
Pair
fields you want to be treated specially.
s

snowe

09/29/2017, 3:53 PM
Yeah I had thought of those other solutions. Thanks for all the advice guys/girls!
👍 1