jsoniter-scala icon indicating copy to clipboard operation
jsoniter-scala copied to clipboard

Call default value method only if null value was parsed for the field

Open plokhotnyuk opened this issue 7 years ago • 1 comments

Currently it is called for all fields in the start of decoding method, for example:

private def d0(in: JsonReader, default: JsonCodecMakerSpec.this.Defaults): JsonCodecMakerSpec.this.Defaults = if (in.isNextToken('{')) {
  var _s: String = Defaults.`<init>$default$1`;
...
  _s = in.readString(_s)

Should be:

private def d0(in: JsonReader, default: JsonCodecMakerSpec.this.Defaults): JsonCodecMakerSpec.this.Defaults = if (in.isNextToken('{')) {
  var _s: String = null;
...
    _s = in.readString(_s)
    if (_s == null) _s = Defaults.`<init>$default$1`;

Or use presence bits in p0, p1, ... , pN variables instead checking for null.

plokhotnyuk avatar Jan 03 '18 09:01 plokhotnyuk

Related to refactoring required for adding support of default values for non-first list of arguments of primary constructors: https://github.com/plokhotnyuk/jsoniter-scala/issues/904

plokhotnyuk avatar Jun 24 '22 12:06 plokhotnyuk