Re: [Json] JSL: Clarifying purpose, and renaming it to JDDF

Ulysse Carion <ulysse@segment.com> Tue, 03 September 2019 02:02 UTC

Return-Path: <ulysse@segment.com>
X-Original-To: json@ietfa.amsl.com
Delivered-To: json@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 7DD351200C4 for <json@ietfa.amsl.com>; Mon, 2 Sep 2019 19:02:24 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.999
X-Spam-Level:
X-Spam-Status: No, score=-1.999 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=segment.com
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XXDTzYU554SK for <json@ietfa.amsl.com>; Mon, 2 Sep 2019 19:02:22 -0700 (PDT)
Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 1AB33120074 for <json@ietf.org>; Mon, 2 Sep 2019 19:02:22 -0700 (PDT)
Received: by mail-io1-xd36.google.com with SMTP id u185so28567562iod.10 for <json@ietf.org>; Mon, 02 Sep 2019 19:02:22 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=segment.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=lwWfb3iq0U2nLSZFGCYQrmGtQMBMPvIFYe88bPSfEp0=; b=VtIM0d5rs1dfoz/knByDfLDE3G8Jej5tWlVFqCl+uz6lI6SKUCsf+vozOnDzxTb0EI QOvMSj7U8+UCgKC4jyMb10pHkR2lyHn6cWN7n4NKYuMrUw36antk7IRPZwCXQihlC4QE ZGpk6fl7MMyPaC9vuZ0Afon/kbCIf3mpawB34=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=lwWfb3iq0U2nLSZFGCYQrmGtQMBMPvIFYe88bPSfEp0=; b=cmm6+Du6rXjPkdi/0v/lbhbVt0a8A+Z+9qhWNMqauP+hKTDeQlAcOMF8N68ckPh/nM 0D1IkKHj8KXfB4YsnHZDNMieiVGwnrE4i+t1KBV3mCtrBfAB9mjPVUx2omaBVyd/xh2M 7KE+DAe8XKVQALSSjqpvRsbU3I7xl1FY2/QW4wU05HdwvbDnQqeyWzIn31Bv9OK7Fr1Y QEVpH9zg2DK2+uRFPEkW9P35HYPro3vzP84pfmvnz9zqY9PdUL4/h+ODhSJZcFmy4zgS KdvmSMUDsEYi/lB2tv9+F8xQiUbE9GkqGQejVYerEp3//ed46TYucSI1um2WaNxge1am UmPw==
X-Gm-Message-State: APjAAAXnqbHSquMnIcKvwEmECXWHM2EM2Nv2ghls6NpLnQ5ZH1CeMwd7 o4WTcurNc91VbaKVwHr/KEYLqs0QymfdR7qmrIzQig==
X-Google-Smtp-Source: APXvYqy6ktTGlx62MIQ8D2ir4ysXQb8L8Tf4dSGNor5btLzNNmLyVRNoSi0sMseLILzQkDcOrngdu6j02fB7GJKFZ8k=
X-Received: by 2002:a6b:7718:: with SMTP id n24mr10003821iom.114.1567476141322; Mon, 02 Sep 2019 19:02:21 -0700 (PDT)
MIME-Version: 1.0
References: <CAJK=1Rj6zW_MffKvsOiQh28KY5yDeoALGSYqve+vGj52s1Owag@mail.gmail.com> <SY2PR01MB2764EDAB3DD01417A95A26D5E5A20@SY2PR01MB2764.ausprd01.prod.outlook.com> <CAJK=1RhFnTqa+9b5M_WrPiEVg_+Prkv_+pazg8y1vACD7PXAkw@mail.gmail.com> <ME2PR01MB27539FF21FFFF4CD23993258E5BE0@ME2PR01MB2753.ausprd01.prod.outlook.com>
In-Reply-To: <ME2PR01MB27539FF21FFFF4CD23993258E5BE0@ME2PR01MB2753.ausprd01.prod.outlook.com>
From: Ulysse Carion <ulysse@segment.com>
Date: Mon, 02 Sep 2019 19:02:09 -0700
Message-ID: <CAJK=1RjhMZ2DsQRCkLWfU3gHn-E6-WvdFFa4Bt+31kumegEBuw@mail.gmail.com>
To: "Manger, James" <James.H.Manger@team.telstra.com>
Cc: JSON WG <json@ietf.org>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Archived-At: <https://mailarchive.ietf.org/arch/msg/json/hPNRPyFkSjFsO6_q2GpcrFRF8Qs>
Subject: Re: [Json] JSL: Clarifying purpose, and renaming it to JDDF
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "JavaScript Object Notation \(JSON\) WG mailing list" <json.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/json>, <mailto:json-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/json/>
List-Post: <mailto:json@ietf.org>
List-Help: <mailto:json-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/json>, <mailto:json-request@ietf.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Sep 2019 02:02:25 -0000

> And even these additions don't make Java's standard sorting or printing work for uint8. Generated code cannot merely using byte for uint8; it also needs to add code so a byte-as-uint8 is serialized differently to a normal byte-as-int8.

It's true that the standard sorting and printing stuff doesn't work
as-is. It's untrue that one cannot merely use byte for uint8, or int
for uint32. gRPC does this. It's quite common to use []byte in a
context where the byte is known, beyond the type system, to represent
unsigned numbers.

Serializing an int back to JSON is a stronger point. But code
generation can deal with this by overriding the relevant
fromJSON/toJSON or equivalent. Both gson and Jackson have such
functionality. This is unpleasant, but handled entirely by the code
generator. But from the user's perspective they have a POJO they can
immediately use, and which behaves correctly with respect to SerDe.
That's what matters most for a code generating tool, in my view.

Having to write special serialization logic happens already for the
discriminator form, and for many languages the timestamp data type.
But the important thing is that the codegen'd code can contain this
nastiness, and automate away having to write such code.

> If I saw uint8 in JDDF, I'd almost certainly want control over whether it became a byte or short in my Java code, depending on the situation.

This is a very sensible position. Sounds like jddf-codegen ought to
support such an option, and equivalents for uint16 and uint32.

> But if the spec is too minimal it isn't worthwhile.

Yes, but as it is I don't think the spec meets this "too minimal" threshold.

On Sun, Sep 1, 2019 at 6:45 PM Manger, James
<James.H.Manger@team.telstra.com> wrote:
>
> >> JDDF offers "type":"uint8" but very common languages, such as Java, don't have an unsigned 8-bit type. So code generation might use a short (16-bit signed integer) to handle the [0, 255] range. That seems to put the code in a very similar situation to using a long when the JDDF says "int54". In both cases the native type can hold values that the schema doesn't allow, requiring extra parse/stringify functions if you really want to enforce the schema's rules.
>
> >This isn't quite right. Yes -- Java only has "byte", but by convention you can store both signed and unsigned 8-bit numbers in these bytes.
> >Protobufs does this:
>
> That is certainly 1 reasonable choice for a code generator.
>
> >Furthermore, the Java standard library has methods that explicitly let you do the conversion of a Java byte-as-uint8 into a Java int or long:
> >
> >https://docs.oracle.com/javase/8/docs/api/java/lang/Byte.html#toUnsignedInt-byte-
> >https://docs.oracle.com/javase/8/docs/api/java/lang/Byte.html#toUnsignedLong-byte-
> >
> >If bytes-as-uint8 weren't conventional, then why does java.lang.Byte have methods that enable such a style?
>
> Did you notice the "Since 1.8" annotation on those methods? This support for byte-as-uint8 was only added in Java 8.
> And even these additions don't make Java's standard sorting or printing work for uint8. Generated code cannot merely using byte for uint8; it also needs to add code so a byte-as-uint8 is serialized differently to a normal byte-as-int8.
>
> Short-as-uint8 has different properties: sorting & serializing works as "normal", but it takes twice as much memory.
>
> If I saw uint8 in JDDF, I'd almost certainly want control over whether it became a byte or short in my Java code, depending on the situation.
>
>
> >> * "type": "intString" ...
> >> * "type": "uintB64u" ...
> >> * "type": "bytesB64" ...
> >> * "type": "bytesB64u" ...
>
> > I think I'm opposed to this suggestion. Adding support for arbitrary binary data is going to be challenging. I think I prefer that we just stick to {"type":"string"}, and then folks can write their own extensions to JDDF to achieve their specific needs. After awhile, the community may perhaps converge on common extensions, or patterns may arise and we can update the JDDF spec.
> >
> >Anything we add to the spec now would have to be supported by all implementations. So I'd prefer we give out a minimal spec to the world, and see where the real world takes it. If we try to solve all problems right away, we may make it too hard for implementations to crop up, ultimately solving no problems for anyone.
>
> But if the spec is too minimal it isn't worthwhile.
>
> --
> James Manger