Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
Add ConfigSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
labianchin committed Jun 18, 2018
1 parent e96e59e commit 6786b94
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flo-freezer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
<groupId>com.twitter</groupId>
<artifactId>chill-java</artifactId>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*-
* -\-\-
* flo-freezer
* --
* Copyright (C) 2016 - 2017 Spotify AB
* --
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* -/-/-
*/

package com.spotify.flo.freezer;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.serializers.MapSerializer;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;

import java.util.HashMap;
import java.util.Map;

public class ConfigSerializer extends Serializer<Config> {

@Override
public void write(Kryo kryo, Output output, Config object) {
MapSerializer serializer = new MapSerializer();
kryo.writeObject(output, object.root().unwrapped(), serializer);
}

@Override
public Config read(Kryo kryo, Input input, Class<Config> type) {
MapSerializer serializer = new MapSerializer();
Map configMap = kryo.readObject(input, HashMap.class, serializer);
return ConfigFactory.parseMap(configMap);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import com.spotify.flo.context.ForwardingEvalContext;
import com.twitter.chill.java.PackageRegistrar;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -127,6 +129,11 @@ private static Kryo getKryo() {
Kryo kryo = new Kryo();
PackageRegistrar.all().apply(kryo);
kryo.register(java.lang.invoke.SerializedLambda.class);
try {
kryo.register(Class.forName("com.typesafe.config.impl.SimpleConfig"), new ConfigSerializer());
} catch (ClassNotFoundException e) {
LOG.debug("ConfigSerializer not registered", e);
}
kryo.register(ClosureSerializer.Closure.class, new ClosureSerializer());
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
kryo.addDefaultSerializer(Throwable.class, new JavaSerializer());
Expand Down

0 comments on commit 6786b94

Please sign in to comment.