<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Data-Class on afanasev.net</title><link>https://afanasev.net/categories/data-class/</link><description>Recent content in Data-Class on afanasev.net</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Tue, 13 Aug 2019 15:00:00 +0700</lastBuildDate><atom:link href="https://afanasev.net/categories/data-class/feed.xml" rel="self" type="application/rss+xml"/><item><title>Exclude properties from toString() of Kotlin data class (Sekret appx.)</title><link>https://afanasev.net/kotlin/data-class/2019/08/13/kotlin-data-class-tostirng-hide.html</link><pubDate>Tue, 13 Aug 2019 15:00:00 +0700</pubDate><guid>https://afanasev.net/kotlin/data-class/2019/08/13/kotlin-data-class-tostirng-hide.html</guid><description>&lt;p&gt;&lt;em&gt;This post describes how to remove class properties from the &lt;code&gt;toString()&lt;/code&gt; method manually if you prefer not to use the &lt;a href="https://afanasev.net/kotlin-library/2019/08/13/sekret.html"&gt;Sekret&lt;/a&gt; compiler plugin.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Kotlin&amp;rsquo;s data class &lt;code&gt;toString&lt;/code&gt; is generated automatically to include every property defined in the primary constructor. This is convenient for debugging but problematic when some of those properties contain sensitive data — passwords, tokens, PII — that must not appear in logs, crash reports, or analytics pipelines.&lt;/p&gt;
&lt;p&gt;There is no built-in Kotlin mechanism to exclude a specific field from the generated &lt;code&gt;toString&lt;/code&gt; while keeping it in &lt;code&gt;equals&lt;/code&gt;, &lt;code&gt;hashCode&lt;/code&gt;, and &lt;code&gt;copy&lt;/code&gt;. The language does not (yet) offer an annotation equivalent to &lt;code&gt;@Transient&lt;/code&gt; for serialization. The approaches below represent the practical trade-offs available in pure Kotlin, each with distinct implications for class semantics, mutability, and maintainability.&lt;/p&gt;</description></item></channel></rss>