11/*
2- * Copyright 2016-2024 DiffPlug
2+ * Copyright 2016-2025 DiffPlug
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -457,12 +457,11 @@ protected Integer calculateState() throws Exception {
457457 */
458458 public void custom (String name , Closure <String > formatter ) {
459459 requireNonNull (formatter , "formatter" );
460- Closure <String > dehydrated = formatter .dehydrate ();
461- custom (name , new ClosureFormatterFunc (dehydrated ));
460+ custom (name , new ClosureFormatterFunc (formatter ));
462461 }
463462
464463 static class ClosureFormatterFunc implements FormatterFunc , Serializable {
465- private final Closure <String > closure ;
464+ private Closure <String > closure ;
466465
467466 ClosureFormatterFunc (Closure <String > closure ) {
468467 this .closure = closure ;
@@ -472,6 +471,14 @@ static class ClosureFormatterFunc implements FormatterFunc, Serializable {
472471 public String apply (String unixNewlines ) {
473472 return closure .call (unixNewlines );
474473 }
474+
475+ private void writeObject (java .io .ObjectOutputStream stream ) throws java .io .IOException {
476+ stream .writeObject (closure .dehydrate ());
477+ }
478+
479+ private void readObject (java .io .ObjectInputStream stream ) throws java .io .IOException , ClassNotFoundException {
480+ this .closure = (Closure <String >) stream .readObject ();
481+ }
475482 }
476483
477484 /**
0 commit comments