Property annotations in default ctor of data class are ignored ~ any response to this bug?


#1

I wanna add annotations to some properties (specially on those of Date type) in a data class. But the annotations for fields in default ctor of data class are ignored after compilation. Here’s some snippets:

  1. source of data classes:

    data class PipeParam(
    var firmId: String? = null,

     	@JsonSerialize(using = JsonDateSerializer::class)
     	@JsonDeserialize(using = JsonDateDeserializer::class)
     	@JSONField(serializeUsing = DateCodec::class, deserializeUsing = DateCodec::class, format = JsonHelper.FULL_DATE_FORMAT)
     	var surveyDate: Date? = null,
    
     	@JsonSerialize(using = JsonDateSerializer::class)
     	@JsonDeserialize(using = JsonDateDeserializer::class)
     	@JSONField(serializeUsing = DateCodec::class, deserializeUsing = DateCodec::class, format = JsonHelper.FULL_DATE_FORMAT)
     	var buildDate: Date? = null
    

    ) : Serializable {
    }

  2. source for data class DataParam, please note that annotations are added inside the class body out of default ctor:

    data class DataParam(
    var firmId: String? = null,

     	var duration: DataDuration? = DataDuration.DURATION_60_MIN,
     	var durationInt: Int? = 60,
     	var calculating: Boolean? = false,
     	var index: Int = 0,
     	var rows: Int = 2000
    

    ) : Serializable {
    @JsonSerialize(using = JsonDateSerializer::class)
    @JsonDeserialize(using = JsonDateDeserializer::class)
    @JSONField(serializeUsing = DateCodec::class, format = JsonHelper.FULL_DATE_FORMAT)
    var sampleTime1: Date? = null

     @JsonSerialize(using = JsonDateSerializer::class)
     @JsonDeserialize(using = JsonDateDeserializer::class)
     @JSONField(serializeUsing = DateCodec::class, format = JsonHelper.FULL_DATE_FORMAT)
     var sampleTime2: Date? = null
    

    }

  3. decompiled source with jd after compilation:

public final class PipeParam
implements Serializable
{
@Nullable
private String firmId;
@Nullable
private Date surveyDate;
@Nullable
private Date buildDate;

  public PipeParam(@Nullable String firmId, @Nullable @JsonSerialize(using=JsonDateSerializer.class) @JsonDeserialize(using=JsonDateDeserializer.class) @JSONField(serializeUsing=DateCodec.class, deserializeUsing=DateCodec.class, format="yyyy-MM-dd'T'HH:mm:ss.SSSX") Date surveyDate, @Nullable @JsonSerialize(using=JsonDateSerializer.class) @JsonDeserialize(using=JsonDateDeserializer.class) @JSONField(serializeUsing=DateCodec.class, deserializeUsing=DateCodec.class, format="yyyy-MM-dd'T'HH:mm:ss.SSSX") Date buildDate)
  {
	this.firmId = firmId;this.surveyDate = surveyDate;this.buildDate = buildDate;
  }
  
  @Nullable
  public final String getFirmId()
  {
	return this.firmId;
  }
  
  public final void setFirmId(@Nullable String <set-?>)
  {
	this.firmId = <set-?>;
  }
  
  @Nullable
  public final Date getSurveyDate()
  {
	return this.surveyDate;
  }
  
  public final void setSurveyDate(@Nullable Date <set-?>)
  {
	this.surveyDate = <set-?>;
  }
  
  @Nullable
  public final Date getBuildDate()
  {
	return this.buildDate;
  }
  
  public final void setBuildDate(@Nullable Date <set-?>)
  {
	this.buildDate = <set-?>;
  }
  
  public PipeParam()
  {
	this(null, null, null, 7, null);
  }
  
  @Nullable
  public final String component1()
  {
	return this.firmId;
  }
  
  @Nullable
  public final Date component2()
  {
	return this.surveyDate;
  }
  
  @Nullable
  public final Date component3()
  {
	return this.buildDate;
  }
  
  @NotNull
  public final PipeParam copy(@Nullable String firmId, @Nullable @JsonSerialize(using=JsonDateSerializer.class) @JsonDeserialize(using=JsonDateDeserializer.class) @JSONField(serializeUsing=DateCodec.class, deserializeUsing=DateCodec.class, format="yyyy-MM-dd'T'HH:mm:ss.SSSX") Date surveyDate, @Nullable @JsonSerialize(using=JsonDateSerializer.class) @JsonDeserialize(using=JsonDateDeserializer.class) @JSONField(serializeUsing=DateCodec.class, deserializeUsing=DateCodec.class, format="yyyy-MM-dd'T'HH:mm:ss.SSSX") Date buildDate)
  {
	return new PipeParam(firmId, surveyDate, buildDate);
  }
  
  public String toString()
  {
	return "PipeParam(firmId=" + this.firmId + ", surveyDate=" + this.surveyDate + ", buildDate=" + this.buildDate + ")";
  }
  
  public boolean equals(Object paramObject)
  {
	if (this != paramObject)
	{
	  if ((paramObject instanceof PipeParam))
	  {
		PipeParam localPipeParam = (PipeParam)paramObject;
		if ((!Intrinsics.areEqual(this.firmId, localPipeParam.firmId)) || (!Intrinsics.areEqual(this.surveyDate, localPipeParam.surveyDate)) || (!Intrinsics.areEqual(this.buildDate, localPipeParam.buildDate))) {}
	  }
	}
	else {
	  return true;
	}
	return false;
  }
}
  1. and log for json serialization. please note DataParam json defines annotated properties out of default constructor. so annotations on #buildDate in PipeParam does not work, while annotations on #sampleTime1 in data class DataParam work fine.
    pipe json: {“buildDate”:1521161612689,“firmId”:“1”}
    data json: {“calculating”:false,“duration”:“DURATION_60_MIN”,“durationInt”:60,“firmId”:“21”,“index”:0,“rows”:2000,“sampleTime1”:“2018-03-16T08:53:32.800+08”}