Skip to content

Commit

Permalink
Fix EnumMap serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jan 23, 2024
1 parent 77c8307 commit 797d727
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.conveyal.kryo.TIntArrayListSerializer;
import com.conveyal.kryo.TIntIntHashMapSerializer;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.serializers.EnumMapSerializer;
import com.esotericsoftware.kryo.serializers.ExternalizableSerializer;
import com.esotericsoftware.kryo.util.DefaultInstantiatorStrategy;
import com.google.common.collect.ArrayListMultimap;
Expand All @@ -12,6 +13,7 @@
import gnu.trove.impl.hash.TPrimitiveHash;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.hash.TIntIntHashMap;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -22,6 +24,7 @@
import org.opentripplanner.kryo.UnmodifiableCollectionsSerializer;
import org.opentripplanner.standalone.config.BuildConfig;
import org.opentripplanner.standalone.config.RouterConfig;
import org.opentripplanner.street.search.TraverseMode;

public final class KryoBuilder {

Expand Down Expand Up @@ -57,6 +60,7 @@ public static Kryo create() {
kryo.register(Set.of(1).getClass(), new JavaImmutableSetSerializer());
kryo.register(Map.of().getClass(), new JavaImmutableMapSerializer());
kryo.register(Map.of(1, 1).getClass(), new JavaImmutableMapSerializer());
kryo.register(EnumMap.class, new EnumMapSerializer(TraverseMode.class));

kryo.register(HashMultimap.class, new HashMultimapSerializer());
kryo.register(ArrayListMultimap.class, new ArrayListMultimapSerializer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import java.io.ObjectOutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
Expand Down Expand Up @@ -67,6 +69,8 @@ public class StreetEdge

private StreetEdgeCostExtension costExtension;

private Map<TraverseMode, Float> enumMapTest = new EnumMap<>(TraverseMode.class);

/** back, roundabout, stairs, ... */
private short flags;

Expand Down Expand Up @@ -146,6 +150,8 @@ protected StreetEdge(StreetEdgeBuilder<?> builder) {
inAngle = lineStringInOutAngles.inAngle();
outAngle = lineStringInOutAngles.outAngle();
elevationExtension = builder.streetElevationExtension();
enumMapTest.put(TraverseMode.WALK, 20438f);
enumMapTest.put(TraverseMode.SCOOTER, 23438f);
}

public StreetEdgeBuilder<?> toBuilder() {
Expand Down

0 comments on commit 797d727

Please sign in to comment.