# How did Kotlin design Object so that deserialization still only exists as a singleton

**URL:** <https://discuss.kotlinlang.org/t/how-did-kotlin-design-object-so-that-deserialization-still-only-exists-as-a-singleton/29472>\
**Category:** Language Design\
**Created:** [November 3, 2024, 2:22pm UTC](https://discuss.kotlinlang.org/t/how-did-kotlin-design-object-so-that-deserialization-still-only-exists-as-a-singleton/29472 "2024-11-03T14:22:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Setruth\_Yang](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/setruth_yang/32/10994_2.png) [@Setruth\_Yang](https://discuss.kotlinlang.org/u/Setruth_Yang)\
**Post date:** [November 3, 2024, 2:22pm UTC](https://discuss.kotlinlang.org/t/how-did-kotlin-design-object-so-that-deserialization-still-only-exists-as-a-singleton/29472/1 "2024-11-03T14:22:19Z")

</div>

Recently,I am write about desgin pattern article,in single pattern, I use “object” to create single instancce . When I try to deserialize to get a new instance, I find that getting the instance or the previous one, and not creating a new one, how is this done I want to know.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/4/4a2a0935569247d0d256dedb59c0033ce2d8fccf.png)

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [November 3, 2024, 2:42pm UTC](https://discuss.kotlinlang.org/t/how-did-kotlin-design-object-so-that-deserialization-still-only-exists-as-a-singleton/29472/2 "2024-11-03T14:42:22Z")

</div>

First of all, don’t provide code samples as images. It makes impossible for readers to use the code easily.

Second, it really depends on the serialization library you use. Kotlin can’t control how `parseObject` works internally. Some libraries could return the singleton object, some could return additional instances, some could fail in this case.

I suspect in your case this is the second scenario, so you don’t actually get the singleton, but another instance. Please check `Single === newSingle`. It works because `name` is static, so all instances reference the same value.
