From user-return-22401-archive-asf-public=cust-asf.ponee.io@flink.apache.org Mon Aug 27 10:29:12 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 1677A180674 for ; Mon, 27 Aug 2018 10:29:11 +0200 (CEST) Received: (qmail 63527 invoked by uid 500); 27 Aug 2018 08:29:10 -0000 Mailing-List: contact user-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list user@flink.apache.org Received: (qmail 63517 invoked by uid 99); 27 Aug 2018 08:29:10 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Aug 2018 08:29:10 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 86E7FC1E0D for ; Mon, 27 Aug 2018 08:29:10 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.869 X-Spam-Level: * X-Spam-Status: No, score=1.869 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, T_DKIMWL_WL_MED=-0.01] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 9lepXzrxjDuv for ; Mon, 27 Aug 2018 08:29:09 +0000 (UTC) Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 40BA15F35A for ; Mon, 27 Aug 2018 08:29:09 +0000 (UTC) Received: by mail-wm0-f45.google.com with SMTP id y2-v6so7235597wma.1 for ; Mon, 27 Aug 2018 01:29:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IQQxW1Cn8UAnYpB8OlmwDRCE8Ql9ASrBEdluYk1hVFU=; b=Jlnm4v2QxToyT5JkcirJKm5dRyOvlIyTe1mupA6UMxIdA6LRqXbf8Pawq6fXIu74mn pzc24xHDUw30+FnsAtiGON1477yhGg6jnH+wZHHcqlZu3SSAPmcwM3FE1w1p3TMsDY+m yUEJsqLIstjNNVXji0afOGu3J/YxmTFWPYc4clReu7yZgxc5vnZWrBsygKuGhj9OMhFF 83Zb7ILGMiUxzGOegYBlLAsY4+fzQQrbHaRHiOjl4E/uG7VH8ItkHMZTmYYwLYRgwrHu lN6iSPyB+2hv6gaS8rA0Wlsd7l3+AQYBLBdZfHzNqNmsvr0LIquqRL2Zx2+Cfgm0fg1e NWVA== 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; bh=IQQxW1Cn8UAnYpB8OlmwDRCE8Ql9ASrBEdluYk1hVFU=; b=nuJNin3t3FRoWSW5G+59Vu4kmqGfBdh5Z7SJfsWG2cuSbyL5KIOs13GvlKh2hcpCWl H4K6avmN34ZCYh1OVpqkrHd8tSszvgVeYI6EgT6WlbzlQ7RMoJt2V4SKxjgkOyt9dbOo KR75zG5wWJknrQzBxtca2YULI90b99u7vPtdWaijOZ5rbIMujdgGijzpNXBTqlVVPZcO xip4lfDk5cmzLlI7mBPtzZWPBFWaO9jVjwWaPqWIdnSQixwNO9vMEkstTf6TE/+Arguh QGyODZ7kUF1sHUru3jzt89YCxzA3OsRgiDxTGz3OVoSNY8WA2gm/ppdMskD5gV18Ep1P jVtQ== X-Gm-Message-State: APzg51AqbRvkuWKdP9xhmvJSIk7Wac7F5LTNKrxozoKvfzLxm0uHIPYP Yft1rJXOtZH/o9O+sNFepb6wLo8LQbX2VNkXoQI= X-Google-Smtp-Source: ANB0VdYT5FTwncECcxxN5rVB6XTVrryhYJU4C/VTdMPpkvKujp9eU84qI0U6juXqwS5KJll/RlMmGWrXfOjGYFFfC9A= X-Received: by 2002:a1c:9751:: with SMTP id z78-v6mr4809268wmd.9.1535358548219; Mon, 27 Aug 2018 01:29:08 -0700 (PDT) MIME-Version: 1.0 References: <0e39fd9c-cbeb-51db-a97f-0c7e675d30f4@apache.org> In-Reply-To: <0e39fd9c-cbeb-51db-a97f-0c7e675d30f4@apache.org> From: =?UTF-8?Q?Dominik_Wosi=C5=84ski?= Date: Mon, 27 Aug 2018 10:28:56 +0200 Message-ID: Subject: Re: Dealing with Not Serializable classes in Java To: chesnay@apache.org Cc: user Content-Type: multipart/alternative; boundary="000000000000de9ace05746684f0" --000000000000de9ace05746684f0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey Paul, Yeah that is possible, but I was asking in terms of serialization schema. So I would really want to avoid RichFunction :) Best Regards, Dominik. pon., 27 sie 2018 o 10:23 Chesnay Schepler napisa=C5= =82(a): > The null check in the method is the general-purpose way of solving it. > If the ObjectMapper is thread-safe you could also initialize it as a > static field. > > On 26.08.2018 17:58, Dominik Wosi=C5=84ski wrote: > > Hey, > > I was wondering how do You normally deal with fields that contain > references that are not serializable. Say, we have a custom serialization > schema in Java that needs to serialize *LocalDateTime* field with > *ObjectMapper.* This requires registering specific module for > *ObjectMapper* and this makes it not serializable (module contains some > references to classes that are not serializable). > Now, if You would initialize *ObjectMapper *directly in the field this > will cause an exception when deploying the job. > > Normally I would do : > > @Overridepublic byte[] serialize(Backup backupMessage) { > if(objectMapper =3D=3D null) { > objectMapper =3D new ObjectMapper().registerModule(new JavaTimeMo= dule()); } > ... > } > > But I was wondering whether do You have any prettier option of doing this= ? > > Thanks, > Dominik. > > > --000000000000de9ace05746684f0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hey Paul,
Yeah that is possible, but I was asking in te= rms of serialization schema. So I would really want to avoid RichFunction := )

Best Regards,
Dominik.

pon., 27 sie 2018 o 10:23=C2=A0Chesnay Schepler <chesnay@apache.org> napisa=C5=82(a):
=
=20 =20 =20
The null check in t= he method is the general-purpose way of solving it.
If the ObjectMapper is thread-safe you could also initialize it as a static field.

On 26.08.2018 17:58, Dominik Wosi=C5=84ski wrote:
Hey,=C2=A0

I was wondering how do You normally deal with fields that contain references that are not serializable. Say, we have a custom serialization schema in Java that needs to serialize Loca= lDateTime=C2=A0field with ObjectMapper.=C2=A0 This requires registering specific module for ObjectMapper=C2=A0and this makes it not serializable (module contains some references to classes that are not serializable).=C2=A0
Now, if You would initialize ObjectMapper directly in the field this will cause an exception when deploying the job.=C2= =A0

Normally I would do :=C2=A0
@Override
public byte[] serialize(Backup backupMessage) {
    if(objectMapper =3D=3D null) {
        objectMapper =3D new ObjectMapper().registerModule(=
new JavaTimeModule());
    }
...
}
But I was wondering whether do You have any prettier option of doing this?=C2=A0

Thanks,
Dominik.


--000000000000de9ace05746684f0--