From 797d7276ee3e13f35d5bdc6c90bacc7f13a01513 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Tue, 23 Jan 2024 14:26:06 +0100 Subject: [PATCH] Fix EnumMap serialization --- .../routing/graph/kryosupport/KryoBuilder.java | 4 ++++ .../org/opentripplanner/street/model/edge/StreetEdge.java | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/org/opentripplanner/routing/graph/kryosupport/KryoBuilder.java b/src/main/java/org/opentripplanner/routing/graph/kryosupport/KryoBuilder.java index d094f8c945f..c53e5ecc96e 100644 --- a/src/main/java/org/opentripplanner/routing/graph/kryosupport/KryoBuilder.java +++ b/src/main/java/org/opentripplanner/routing/graph/kryosupport/KryoBuilder.java @@ -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; @@ -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; @@ -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 { @@ -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()); diff --git a/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java b/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java index 1e3594ee04b..2fb275903d5 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java +++ b/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java @@ -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; @@ -67,6 +69,8 @@ public class StreetEdge private StreetEdgeCostExtension costExtension; + private Map enumMapTest = new EnumMap<>(TraverseMode.class); + /** back, roundabout, stairs, ... */ private short flags; @@ -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() {