flink-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chesnay Schepler <ches...@apache.org>
Subject Re: Dealing with Not Serializable classes in Java
Date Mon, 27 Aug 2018 08:23:37 GMT
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Ƅski 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 :
> @Override public byte[]serialize(Backup backupMessage) {
>      if(objectMapper ==null) {
>          objectMapper =new ObjectMapper().registerModule(new JavaTimeModule()); }
> ...
> }
> But I was wondering whether do You have any prettier option of doing 
> this?
>
> Thanks,
> Dominik.



Mime
View raw message